Options
All
  • Public
  • Public/Protected
  • All
Menu

zfetchz

fetch has timeout and interceptor; Doc: https://klren0312.github.io/zfetch/

NPM version npm

Install

$ npm install zfetchz --save

Build

$ npm run build

Test

$ npm run test

Usage

1.Init

If use it in Browser, you should use in browser' in first param; Else if you use it in NodeJS, you should use 'node' in first param. The second param is timeout, when you fetch data

const z = new zfetchz('browser', 2000);

2.config interceptor (Default no interceptor)

var zfetchzInterceptor = z.interceptor
zfetchzInterceptor.register({
  request: function (...request) {
    console.log('request', request)
    return request
  },
  response: function (response) {
    console.log('response', response)
    return response
  }
})

3.If you want to unregister the interceptor, you should assign it to a variable, then call it

const unregister = zfetchzInterceptor.register({
  request: function (...args: any[]) {
    return args;
  }
});

unregister();

4.Fetch data

z.newFetch('https://cnodejs.org/api/v1/topics', {
  headers: new Headers({
    'content-type': 'application/json'
  })
})
.then(res => res.json())
.then(res => {
  console.log(res)
})

Example

in /example/index.html

Index

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc