npm.io
1.0.2 • Published 4 years ago

@notthedom/js-fetch

Licence
MIT
Version
1.0.2
Deps
1
Size
2 kB
Vulns
1
Weekly
0
Stars
1

@notthedom/js-fetch

Maybe the smallest module of all time

Wrapper around node-fetch that appends .then(res => res.json()) for you

Example usage

import jsFetch from '@notthedom/js-fetch';

const URL = 'https://api.someone/endpoint';
const AUTH = {
  headers: {
    authorization: `Bearer ${mySecretBearerToken}`,
  },
};

// no more repetitive typing of .then(res => res.json()) or equivalent
const data = await jsFetch(URL, AUTH);

// data is now ready to consume as a beautiful JS object
Note on error handling
  • The module appends .then() but no .catch() to a request

  • Assumed usage with async/await

  • Therefore left it to the user to implement typical try/catch, or their preferred error handling strategy.

Keywords