🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

vufetch

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vufetch

A fetch wrapper, supports timeout, interceptor and retry

latest
Source
npmnpm
Version
0.1.13
Version published
Maintainers
1
Created
Source

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

Keywords

axios

FAQs

Package last updated on 23 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts