2.0.1 • Published 4 years ago

@eneto/axios-es6-class v2.0.1

Weekly downloads
8
License
Apache-2.0
Repository
-
Last release
4 years ago

axios-es6-class

npm version install size npm downloads

© Apache-2.0 License

axios es6 class is a typescript module that implements axios to use it as a "modern" JavaScript TypeScript class.

how-to-use-axios-typescript-like-a-pro

first we need to install it:

$ npm i @eneto/axios-es6-class

for the baseUrl and for the timeout. we recommend to set on your .env file

...
API_BASE_URL=https://www.domain.com
API_TIMEOUT=15000

API_BASE_URL: baseUrl from axios request config. API_TIMEOUT: milliseconds the api should wait before throwing an Timeout exception

NOTE: you need to bind your APIs endpoint in the constructor of your controller

detail example

export class UserApi extends Api {
    constructor (config) {
        // if you DO NOT pass any parameter.
        // make sure to have an API_BASE_URL env variable
        super(config);

        this.login = this.login.bind(this);
    }

    login (credentials) {
        return this.post("/users", credentials)
            .then(this.success)
    }
}
2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago