1.1.3 • Published 2 years ago

@glomex/custom-fetch v1.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@glomex/custom-fetch

A convenience wrapper for fetch, which can be used in node and in the browser.

It handles the following things:

  • Automatically assumes that Content-Type': application/json is used (encodes body with JSON.stringify and automatically resolves the response with .json())
  • Allows to pass a timeout

Usage

Node

It ensures to load node-fetch and abort-controller as necessary.

const fetch = require('@glomex/custom-fetch');
fetch(
  'https://my-endpoint',
  // also see https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
  { method: 'GET' },
  { timeout: 5000 }
);

Browser

import fetch from 'https://unpkg.com/@glomex/custom-fetch@1/dist/custom-fetch.modern.js';
fetch(
  'https://my-endpoint',
  // also see https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
  { method: 'GET' },
  { timeout: 5000, responseType: 'text' }
);

License

Apache 2.0 License

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago