fetch-json-timeout

7.0.0 • Public • Published

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);

/fetch-json-timeout/

    Package Sidebar

    Install

    npm i fetch-json-timeout

    Weekly Downloads

    7

    Version

    7.0.0

    License

    Apache-2.0

    Unpacked Size

    15.5 kB

    Total Files

    7

    Last publish

    Collaborators

    • gumm