@chookscord/fetch
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@chookscord/fetch

A small wrapper around node-fetch@3 that provides CommonJS support and a few extra utilities.

Installation

node-fetch is added as a peer dependency, so node-fetch@2 should also work.

yarn add @chookscord/fetch node-fetch

Utilities

HTTP Methods

const { fetch } = require('@chookscord/fetch');

// Plain POST request
fetch('https://example.com', { method: 'POST' });

// Using the utility POST request method
// Other methods are available as well
fetch.post('https://example.com');

Consuming body

const { fetch } = require('@chookscord/fetch');

// Sending a get request and consuming the json body
fetch('https://example.com')
  .then(res => res.json())
  .then(data => console.log(data));

// Same as above but using utility methods
// text(), blob(), and arrayBuffer() are also available
fetch('https://example.com')
  .json()
  .then(data => console.log(data));

Chaining

const { fetch } = require('@chookscord/fetch');

// Send a POST request and consume the response body as json
fetch
  .post('https://example.com')
  .json()
  .then(data => console.log(data));

License

MIT

Package Sidebar

Install

npm i @chookscord/fetch

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.95 kB

Total Files

4

Last publish

Collaborators

  • chooks22