yab-fetch
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.5 • Public • Published

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;

Liscense

MIT

/yab-fetch/

    Package Sidebar

    Install

    npm i yab-fetch

    Weekly Downloads

    0

    Version

    0.0.1-alpha.5

    License

    MIT

    Unpacked Size

    70 kB

    Total Files

    30

    Last publish

    Collaborators

    • leohxj
    • stonexer
    • xianchen