0.1.13 • Published 2 years ago

vufetch v0.1.13

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

vufetch

npm version A fetch wrapper, supports timeout, interceptor and retry

installation

npm install vufetch --save  

usage

import * as vufetch from 'vufetch'

const myFetch = vufetch.create({
    // common options
    baseURL: 'https://www.example.com',
    timeout: 10000,  // default 1 min
    // interceptors
    onRequest(options) {
        return options
    },
    onRequestError(err) {
        return Promise.reject(err)
    },
    onResponse(data) {
        // handle data
        // ...
        return data
    },
    onResponseError(err) {
        return Promise.reject(err)
    },
})
myFetch.get('/users', {
    retry: true,
})
.then(console.log)
.catch(err => {
    // we use AbortController API to abort request to fit timeout, so you can use error.aborted to judge whether the request is timeout
    if (err.aborted) {
        // ...
    }
    console.log(err)
})

License

MIT

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago