Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Latest commit

 

History

History
97 lines (67 loc) · 1.95 KB

README.md

File metadata and controls

97 lines (67 loc) · 1.95 KB

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

createFetch(url[, options])

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
}

Instance methods

import { createFetch } from 'yab-fetch';
const instance = createFetch();

instance.get(url[, options]); // HTTP GET
instace.post(url[, options]); // HTTP POST

Middleware

yab.use(middleware)

import { createFetch } from 'yab-fetch';
const instance = createFetch();

instance.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