@eneto/axios-es6-class
v2.0.1
Published
es6 axios class
Downloads
18
Readme
axios-es6-class
© 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
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)
}
}