Skip to content

A wrapper around node-fetch to get JSON with the option of timing out.

Notifications You must be signed in to change notification settings

gumm/fetch-json-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch-json-timeout

Version 4

v4 is a major update that will break existing implementations. In particular, it returns a promise instead of an object when invoked:

import fetchJson from 'fetch-json-timeout';

const fetcher = await fetchJson();
const data = await fetcher('GET', url);

v4 also supports opinionated JWT token authentication, and refresh. Internally it keeps track of token expiery and refreshes it if it had expired.

import fetchJson from 'fetch-json-timeout';
const jwtOpts = {
  "uri":"https://some.api.endpoint/api/v3/tokens/login/",
  "refreshUri": "https://some.api.endpoint/api/v3/tokens/refresh/",
  "verb": "POST",
  "payload": {
    "email": "some.email@address.org",
    "password": "some_fancy_obscure_password"
  }
}

const fetcher = await fetchJson(undefined, undefined, jwtOpts);
const data = await fetcher('GET', url);

About

A wrapper around node-fetch to get JSON with the option of timing out.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published