npm.io
7.0.2 • Published 6 years ago

apiz-browser-client

Licence
MIT
Version
7.0.2
Deps
2
Size
49 kB
Vulns
0
Weekly
0

apiz-browser-client

apiz-browser-client implements the APIzClient interface for browser, based on tinyjx, so you can use options of tinyjx.

Usage

import { APIz } from 'apiz-ng';
import apizClient from 'apiz-browser-client';

const apiMeta = {
    getBook: {
        url: 'http://www.a.com'
    }
};

const apis = new APIz(apiMeta, {
    client: apizClient({
        beforeSend(xhr) {
            return false;
        },
        afterResponse(resData, status, xhr, url, reqData) {
            console.log(resData);
        },
        complete(resData, xhr, url, reqData) {
            console.log(resData);
        },
        retry: 3
    })
});

apis.getBook().then(({data, next}) => {
    console.log(data);
    next();
})

beforeRequest and afterResponse are hooks of tinyjx.

Keywords