# yab-fetch

> A fetch library.

Latest version **0.0.1-alpha.5** (published 2019-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install yab-fetch
pnpm add yab-fetch
yarn add yab-fetch
bun add yab-fetch
```

## Health

**Score 45/100 (D)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.5 |
| Published | 2019-08-18 |
| First published | 2019-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 68.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | leohxj, stonexer, xianchen |

## Links

- npm: https://www.npmjs.com/package/yab-fetch
- Repository: https://github.com/mjolnirjs/yab/tree/master/packages/yab-fetch
- Issues: https://github.com/mjolnirjs/yab/issues
- npm.io page: https://npm.io/package/yab-fetch

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^6.7.0
- [koa-compose](https://npm.io/package/koa-compose.md) ^4.1.0
- [lodash.omit](https://npm.io/package/lodash.omit.md) ^4.5.0

## Recent versions

- 0.0.1-alpha.5 (latest) — 2019-08-18
- 0.0.1-alpha.4 — 2019-08-10
- 0.0.1-alpha.3 — 2019-07-29
- 0.0.1-alpha.1 — 2019-07-28
- 0.0.1-alpha.0 — 2019-07-28

## README

# yab-fetch

A fetch library.

## Table of Content

- [Features](#features)
- [Browser Support](#browser-support)
- [Install](#install)
  - [npm](#npm)
  - [yarn](#yarn)
  - [CDN](#cdn)
- [Useage](#useage)
  - [createYab(url[, options])](#createYaburl-options)
  - [Instance methods](#yab-methods)
  - [Middleware](#middleware)
    - [yab.use(middleware)](#yabusemiddleware)
    - [middleware function](#middleware-function)
- [Type usage with TypeScript](#type-usage-with-typescript)
- [Liscense](#liscense)

## Features

- **Middleware**: [koa](https://koajs.com/)-like middleware.
- **Fetch**: base on browser [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) API.
- **TypeScript**: Everything in Typescript.

## Browser Support

This library can only be used in modern browser environment. [Polyfill](https://github.com/github/fetch) may be needed.

## Install

### npm

`npm install yab-fetch`

### yarn

`yarn add yab-fetch`

### CDN

```html
<script src="https://unpkg.com/yab-fetch.min.js"></script>
```

## Useage

### createYab(url[, init])

init:

```js
{
  baseUrl: '', // base url
  data: {}, // post data
  use: [], // middlewares
  resolveData: (ctx) => {} // resolve data from ctx
  responseType: 'json'|'text'| 'arrayBuffer' | 'blob' // auto resolve
  before: (request) => {} // handle request before fetch
  after: (response) => {} // handle response after fetch
}
```

### Instance methods

```ts
import { createYab } from 'yab-fetch';
const yab = createYab();

yab.get(url[, init]);
yab.post(url[, init]);
// ...
```

### Middlewares

#### yab.use(middleware)

```ts
import { createYab } from 'yab-fetch';

const yab = createYab();

yab.use(async (ctx, next) => {
  await next();
});
```

#### middleware function

## Type usage with TypeScript

This module is written in TypeScript and the types are published to npm;

## Liscense

[MIT](http://opensource.org/licenses/MIT)

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