# main-client

> custom api

Latest version **1.1.1** (published 2022-11-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install main-client
pnpm add main-client
yarn add main-client
bun add main-client
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-11-21 |
| First published | 2022-11-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | razmik179 |

## Links

- npm: https://www.npmjs.com/package/main-client
- Repository: https://github.com/Raz-Danielyan/main-client
- Homepage: https://github.com/Raz-Danielyan/main-client#readme
- Issues: https://github.com/Raz-Danielyan/main-client/issues
- npm.io page: https://npm.io/package/main-client

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.1.3

## Recent versions

- 1.1.1 (latest) — 2022-11-21
- 1.1.0 — 2022-11-21
- 1.0.9 — 2022-11-16
- 1.0.8 — 2022-11-16
- 1.0.7 — 2022-11-16
- 1.0.6 — 2022-11-16
- 1.0.4 — 2022-11-15
- 1.0.3 — 2022-11-15
- 1.0.2 — 2022-11-15
- 1.0.1 — 2022-11-14
- 1.0.0 — 2022-11-14

## README

# Main Client

This customizing Axios code will help you forget messy and not understandable code. It's clean and easy-working code ** and it will make the world a better place:) **

## Props

- headers => headers is a prop for writing headers in the request, for example when you want to add Authorization in your request header,
- statusHandler => It`s object with functions for error response statuses, for example in 404 error you should have a object

```javascript
{
  on404: () => {
    // do something when 404 error occurs.
  };
}
```

as you already understand it's understood from the object name the error status and the function will work only in that status always, it's should starts with ** on ** and the default error responding key is "defaultErrHandler".

- accessToken => accessToken is a string for getting the Authorization token,
- type => the type is an array to get the user API, for example, if the type is ['update'], it will return only the Promise function to update the backend. by default it will return all methods. And options are (getMany, getOne, update, add, delete).

## Usage

- API_ROOT => It's a base API of your API. For example https://www.youtube.com/watch?v=a8CwpGARAsQ this is whole API and https://www.youtube.com is base API, and you should add API_ROOT in your `.env` file,
- Provider => Provider helps you to customize your API, and after initialization of the Provider you can add an endpoint.

this is a basic example how you can configure your main-client

```javascript
import APIProvider from "main-client";

const accessToken = 'qwe123';

const statusHandler={
  on404:()=>{
    //  do something when 404 error occurs.
  }
  defaultErrHandler:()=>{
    //  do something when error occurs.
  }
}

const type = ['getMany','update'];

const headers = {
  isAdmin: 'true'
};

const provider = APIProvider({ headers, accessToken, statusHandler });

const [fetchAllUnitsApi, updateUnitApi] = provider('units', type);
```

---
_Source: https://npm.io/package/main-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
