A fetch library.
- Middleware: koa-like middleware.
- Fetch: base on browser fetch API.
- TypeScript: Everything in Typescript.
This library can only be used in modern browser environment. Polyfill may be needed.
npm install yab-fetch
yarn add yab-fetch
<script src="https://unpkg.com/yab-fetch.min.js"></script>
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
}
import { createYab } from 'yab-fetch';
const yab = createYab();
yab.get(url[, init]);
yab.post(url[, init]);
// ...
import { createYab } from 'yab-fetch';
const yab = createYab();
yab.use(async (ctx, next) => {
await next();
});
This module is written in TypeScript and the types are published to npm;