# axios-api-lib

> API request Library Based on Axios

Latest version **0.1.1** (published 2020-12-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install axios-api-lib
pnpm add axios-api-lib
yarn add axios-api-lib
bun add axios-api-lib
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-12-03 |
| First published | 2020-12-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | guokai |
| Maintainers | feimao9090 |
| Keywords | axios, api |

## Links

- npm: https://www.npmjs.com/package/axios-api-lib
- Repository: https://github.com/feimao90/Axios-Api-Lib
- Homepage: https://github.com/feimao90/Axios-Api-Lib#readme
- Issues: https://github.com/feimao90/Axios-Api-Lib/issues
- npm.io page: https://npm.io/package/axios-api-lib

## Dependencies (1)

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

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-12-03
- 0.1.0 — 2020-12-03

## README

# Axios Api Library

English | [简体中文](./README-ZH.md)

API request Library Based on Axios

## Table of Contents

- [Install](#install)
- [Usage](#usage)
  - [Basic](#basic)
  * [Configure Axios](#configure-axios)
  * [Sample API Configuration](#sample-api-configuration)

## Install

```bash
$ npm i axios-api-lib

#or

$ yarn add axios-api-lib
```

## Usage

### Basic

**api.js**

```js
import { request } from 'axios-api-lib'

import user from './user'

request.use('user', user)

request.user.fetch()
```

**user.js**

```js
export default {
  fetch: 'http://example.com/users',
}
```

### Configure Axios

```js
import { http, request } from 'axios-api-lib'

// [Global axios defaults](https://github.com/axios/axios#global-axios-defaults)
http.defaults.baseURL = 'http://example.com'

// Interceptors request response
http.interceptors.request.use()

http.interceptors.response.use()

// Finally call request.setHttp method
let req = request.setHttp(http)

// set shake proof
let req = req.setConfig({ shake: 1 })

export { http, req }
```

### Sample API Configuration

**Configuration**

```js
// user.js
export default {
  // Get Request
  fetch: {
    url: 'users',
    method: 'get',
  }
  // Put Request and Dynamic URL
  update: {
    url: 'user/:id',
    method: 'put'
  }
}
```

**Invoking**

```js
const [err, data] = await api.user.fetch({ params: { page: 1, pageSize: 30 } })

const [err, data] = await api.user.update({ data: { id: 1, nickname: 'Tom' } })
```

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