Skip to content

stevebinder/request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Request

A Javascript function for making cancelable requests.

Simple Usage

  try {
    const { data, headers } = await request('data.json');
  } catch (e) {
    const { message, status } = e;
  }

Event Listening

  request({
    url: 'http://example.com/data.json',
    events: {
      error: e => console.log(e.message),
      initialize: e => {},
      load: e => console.log(e.headers, e.data),
      progress: e => console.log(e.bytes, e.total),
    },
  });

Cancelling a Request

  request({
    url: 'http://example.com/data.json',
    events: {
      initialize: e => {
        const pendingRequest = e.target;
        setTimeout(() => pendingRequest.abort(), 2000);
      },
    },
  });

About

Promisable, cancellable, network requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published