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>
options:
{
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 { createFetch } from 'yab-fetch';
const instance = createFetch();
instance.get(url[, options]); // HTTP GET
instace.post(url[, options]); // HTTP POST
import { createFetch } from 'yab-fetch';
const instance = createFetch();
instance.use(async (ctx, next) => {
await next();
});
This module is written in TypeScript and the types are published to npm;