/axios-client-builder

Helper library to build axios clients and extend handling of errors, middleware etc.

Primary LanguageTypeScript

Contributors Forks Stargazers Issues MIT License LinkedIn


Axios Client Builder

This is a http client builder that is based around the Axios http client. The package provides an interface that can extend the axios client for some use cases such as: common error handling, logging and dynamic authorization.

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

Getting Started

Installation

  1. npm i axios-client-builder

(back to top)

Usage

import { ClientBuilder } from 'axios-client-builder';

const client = new ClientBuilder({
    config: { baseURL: env.getUrl() }, // OPTIONAL Axios config object
})
    .addDefaultHeader(key, value)
    .addDefaultHeader(key, fn)
    .addAuthorizationHeader(fn)
    .addErrorHandling(statuses[], fn[])
    .addRequestLogging(logger) // Log requests and timing of requests
    .addErrorLogging(logger) // Log any request error that does not match axios validateStatus
    .build();

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Alex Burley - @burlzad - alex@askconsult.io

Project Link: [https://github.com/alexburley/axios-client-builder](https://github.com/alexburley/axios-client-builder

(back to top)

Acknowledgments

(back to top)