Socket
Socket
Sign inDemoInstall

vufetch

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vufetch

A fetch wrapper, supports timeout, interceptor and retry


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 23 Oct 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc