yab-fetch
v0.0.1-alpha.5
Published
A fetch library.
Downloads
1
Readme
yab-fetch
A fetch library.
Table of Content
Features
- Middleware: koa-like middleware.
- Fetch: base on browser fetch API.
- TypeScript: Everything in Typescript.
Browser Support
This library can only be used in modern browser environment. Polyfill may be needed.
Install
npm
npm install yab-fetch
yarn
yarn add yab-fetch
CDN
<script src="https://unpkg.com/yab-fetch.min.js"></script>
Useage
createYab(url[, init])
init:
{
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
import { createYab } from 'yab-fetch';
const yab = createYab();
yab.get(url[, init]);
yab.post(url[, init]);
// ...
Middlewares
yab.use(middleware)
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;