# @livelybone/easy-request

> A easy-to-use http request library to support all javascript runtime environments. 一个以支持所有JavaScript运行环境为目的、简单易用的http请求库。

Latest version **1.9.1** (published 2020-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @livelybone/easy-request
pnpm add @livelybone/easy-request
yarn add @livelybone/easy-request
bun add @livelybone/easy-request
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.9.1 |
| Published | 2020-07-29 |
| First published | 2020-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 98.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | 2631541504@qq.com |
| Maintainers | livelybone |
| Keywords | http, request, ajax, fetch, browser, node, app, weapp |

## Links

- npm: https://www.npmjs.com/package/@livelybone/easy-request
- Repository: https://github.com/livelybone/easy-request
- Homepage: https://github.com/livelybone/easy-request#readme
- Issues: https://github.com/livelybone/easy-request/issues
- npm.io page: https://npm.io/package/@livelybone/easy-request

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^6.9.1
- [base64-blob](https://npm.io/package/base64-blob.md) ^1.4.1
- [object-to-formdata](https://npm.io/package/object-to-formdata.md) ^3.0.6

## 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

- 1.9.1 (latest) — 2020-07-29
- 1.9.0 — 2020-07-27
- 1.8.0 — 2020-06-19
- 1.7.3 — 2020-06-15
- 1.7.2 — 2020-06-15
- 1.7.1 — 2020-06-09
- 1.7.0 — 2020-06-05
- 1.6.6 — 2020-06-04
- 1.6.5 — 2020-06-04
- 1.6.4 — 2020-06-04
- 1.6.3 — 2020-06-04
- 1.6.2 — 2020-06-04
- 1.6.1 — 2020-06-04
- 1.6.0 — 2020-05-27
- 1.5.1 — 2020-05-26
- … 16 more at https://npm.io/package/@livelybone/easy-request/versions

## README

# @livelybone/easy-request
[![NPM Version](http://img.shields.io/npm/v/@livelybone/easy-request.svg?style=flat-square)](https://www.npmjs.com/package/@livelybone/easy-request)
[![Download Month](http://img.shields.io/npm/dm/@livelybone/easy-request.svg?style=flat-square)](https://www.npmjs.com/package/@livelybone/easy-request)
![gzip with dependencies: 8kb](https://img.shields.io/badge/gzip--with--dependencies-kb-brightgreen.svg "gzip with dependencies: 8kb")
![typescript](https://img.shields.io/badge/typescript-supported-blue.svg "typescript")
![pkg.module](https://img.shields.io/badge/pkg.module-supported-blue.svg "pkg.module")

> `pkg.module supported`, which means that you can apply tree-shaking in you project

[中文文档](./README-CN.md)

A easy-to-use http request library to support all javascript runtime environments.

---
Feature list:
1. Initiate request. customize header, responseType, withCredentials, timeout
2. Cancel the request
3. Receive responses
4. Get the upload/receive progress

## repository
https://github.com/livelybone/easy-request.git

## Demo
https://github.com/livelybone/easy-request#readme

## Run Example
Your can see the usage by run the example of the module, here is the step:

1. Clone the library `git clone https://github.com/livelybone/easy-request.git`
2. Go to the directory `cd your-module-directory`
3. Install npm dependencies `npm i`(use taobao registry: `npm i --registry=http://registry.npm.taobao.org`)
4. Open service `npm run dev`
5. See the example(usually is `http://127.0.0.1:3000/examples/test.html`) in your browser

## Installation
```bash
npm i -S @livelybone/easy-request
```

## Global name - The variable the module exported in `umd` bundle
`EasyRequest`

## Interface
See what method or params you can use in [index.d.ts](./index.d.ts)

## Usage
```js
import { Http, EngineName } from '@livelybone/easy-request'

const http = new Http(
  EngineName.XHR,
  {
    baseURL: 'https://api.hostname.com',
    responseType: 'json',
    headers: { 'Content-Type': 'application/json' },
    method: 'GET',
    timeout: 30000,
    withCredentials: false,
  },
)

// interceptors
http.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) config.headers.Authorization = token
  return config
})

http.interceptors.response.use(response => {
  return response.data
})

const data = { param: '1' }

http.get('/api1').then(res => {
  // ... do something
})

http.get('/api2', data, { responseType: 'text' }).then(res => {
  // ... do something
})

http.post('/api2', data, {
  responseType: 'text',
  headers: { 'Content-Type': 'multipart/form-data' },
}).then(res => {
  // ... do something
})
// ... other methods: put, delete, downloadFile, uploadFile
```

Use in html, see what your can use in [CDN: unpkg](https://unpkg.com/@livelybone/easy-request/lib/umd/)
```html
<-- use what you want -->
<script src="https://unpkg.com/@livelybone/easy-request/lib/umd/<--module-->.js"></script>
```

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