0.1.13 • Published 7 months ago

vufetch v0.1.13

Weekly downloads
-
License
-
Repository
github
Last release
7 months 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

7 months ago

0.1.11

7 months ago

0.1.12

7 months ago

0.1.13

7 months ago

0.1.9

7 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago