3.1.2 • Published 1 year ago

advanced-fetch v3.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
1 year ago

advanced-fetch

GitHub license npm Unit tests workflow status

A version of node-fetch with more convenient functionality.

Installation

npm install advanced-fetch

Usage

const { Fetch } = require("advanced-fetch");

(async () => {
  const fetch = new Fetch();
  await fetch.get("http://example.com");
  // subsequent requests to example.com now send the received
  // cookies again, and the cookies are updated automatically
})();

Constructor

The Fetch constructor expects an optional object, with the following possible attributes:

  • cookiesFilename: If given, the tough-cookie cookie jar is serialized into JSON after each request and that JSON is written into the specified file.
  • encoding: If given, the received responses are assumed to be in that text encoding and converted automatically to UTF-8 via iconv-lite before they are returned to you.

Request parameters

Supports .get, .post, .put and .delete. After the URL, all of these functions also expect an optional object with node-fetch request parameters.

Additionally, you can specify the following parameters as normal JavaScript objects, which are serialized respectively automatically:

  • query for GET query parameters, internally serialized using querystring
  • form for the body of a Content-Type: application/x-www-form-urlencoded request, internally serialized using URLSearchParams
  • formData for the body of a Content-Type: multipart/form-data request, internally serialized using form-data
  • json for the body of a Content-Type: application/json request, internally serialized using JSON.stringify

Finally, you can specify returnBuffer: true in the parameters object in order to get a Node.js Buffer as the result of a request instead of a string.

License

MIT

2.2.1

1 year ago

3.1.2

1 year ago

2.2.0

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.1.0

1 year ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago