# @namphuongtechnologi/axios

## Introduction

This project is designed to facilitate the reusability of Axios libraries. It includes a collection of reusable functions and logics. The main goal of this project is to streamline the development process by providing a set of pre-built elements that can be incorporated into various Axios applications. This not only saves time but also ensures consistency across different projects.

## Usage

```tsx
import { AxiosService, ReqMiddleWare, ResMiddleWare } from '@namphuongtechnologi/axios';
import get from 'lodash/get';

const customResMiddleWare = ResMiddleWare.create<{
  contentTypes: string[];
}>({
  handler: (response, options) => {
    const { contentTypes } = options;

    if (
      contentTypes.includes(response.headers['content-type']) &&
      get(response, 'data.statusCode') !== 200
    ) {
      throw new Error(get(response, 'data.message', 'Bad Request'));
    }

    return response;
  },
});

const axios = new AxiosService({
  baseURL: 'https://api.example.com',
  interceptors: {
    req: {
      middlewares: [
        ReqMiddleWare.removeFields({
          methods: ['put', 'post', 'delete'],
          startWithChar: '__',
        }),
        ReqMiddleWare.convertPascalCase({
          methods: ['put', 'post', 'delete'],
        }),
      ],
    },
    res: {
      middlewares: [
        customResMiddleWare({
          contentTypes: ['application/json'],
        }),
        ResMiddleWare.convertCamelCase({
          contentTypes: ['application/json'],
        }),
      ],
    },
  },
});
```

## Documentation

See the [documentation](https://your-documentation-link.com) for more information on how to use this project.
