This is an axios extension that makes it easier for developers to call the API through the application
- Support standards request:
GET,POST,PATCH,DELETE,PUT. - Allow customize Axios Instance and Error Handling function.
- TypeScript Compatibility.
- Allow extend and modify API wrapper client by implement interfaces and extends base interceptor.
Npm:
npm install @devboostsolution/api-clientYarn:
yarn install @devboostsolution/api-client/** * Step: * 1. Init axios instance * 2. Define errorHandle function * 3. Init axios interceptor * 4. Init axios api client */constaxiosInstance=axios.create({baseURL: process.env.BASE_URL,timeout: 1000,headers: {'Content-Type': 'application/json;charset=utf-8',},});onsterrorHandler=(error: any)=>{if(error.response){console.log(`ErrorHandler is called`);}if(error.response.data){returnerror.response.data;}returnPromise.reject(error);};// Mode: development, production, testconstaxiosInterceptor=newAxiosInterceptor(axiosInstance,errorHandler,'development',);constapiClient=newAxiosApiClient(axiosInterceptor);constresponse=awaitapiClient.get({url: '/api/category'});Clone the repository
make install
npm testDistributed under the MOT license. See LICENSE for more information.
https://github.com/DevBoostSolutions/api-client
Fork it (https://github.com/DevBoostSolutions/api-client/fork)
Create your feature branch (
git checkout -b feature/fooBar)Commit your changes (
git commit -am 'Add some fooBar')Push to the branch (
git push origin feature/fooBar)Create a new Pull Request