Skip to content

Repository files navigation

API-CLIENT

This is an axios extension that makes it easier for developers to call the API through the application

Fetures

  • 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.

Installation

Npm:

npm install @devboostsolution/api-client

Yarn:

yarn install @devboostsolution/api-client

Usage example

Initilze 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'});

Development setup

Clone the repository

make install
npm test

Meta

Distributed under the MOT license. See LICENSE for more information.

https://github.com/DevBoostSolutions/api-client

Contributing

  1. Fork it (https://github.com/DevBoostSolutions/api-client/fork)

  2. Create your feature branch (git checkout -b feature/fooBar)

  3. Commit your changes (git commit -am 'Add some fooBar')

  4. Push to the branch (git push origin feature/fooBar)

  5. Create a new Pull Request

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages