Socket
Socket
Sign inDemoInstall

puppy-fetch

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    puppy-fetch

A small wrapper for the Fetch API that uses the AbortController interface to cancel in-flight fetch requests.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Puppy Fetch

A small wrapper for the Fetch API that uses the AbortController interface to cancel in-flight fetch requests.

Using puppy-fetch helps by making repeated fetch calls abortable by default. This is especially helpful for speeding up the UX for users with a slower internet connection.

Build Status

Edit puppy-fetch

Install

npm install puppy-fetch

or

yarn add puppy-fetch

Usage

  1. import puppyFetch

    import puppyFetch from 'puppy-fetch';
    
  2. Give puppyFetch a unique identifier, and then use it just like you would use the Fetch API.

    const some_unique_string = 'some_unique_string';
    const another_unique_string = 'another_unique_string';
    
    // GET EXAMPLE
    puppyFetch(
      some_unique_string,
      'https://jsonplaceholder.typicode.com/todos/1'
    );
    
    // POST EXAMPLE (note, when aborting, you should not mutate information on the server)
    puppyFetch(another_unique_string, 'https://jsonplaceholder.typicode.com/posts', {
      method: 'POST',
      body: JSON.stringify({
        title: 'foo',
        body: 'bar',
        userId: 1
      }),
      headers: {
        'Content-type': 'application/json; charset=UTF-8'
      }
    });
    

Requests with the same unique identifier will be automatically aborted.


You can polyfill older browsers by running:

npm install --save abortcontroller-polyfill

and then importing the polyfill above your puppy-fetch import:

import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
import puppyFetch from 'puppy-fetch';

See https://www.npmjs.com/package/abortcontroller-polyfill for more information.


More info:

Aborting an instance of a finished request does nothing, and therefore is fine to do.

Keywords

FAQs

Last updated on 04 May 2020

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