3.1.2 • Published 3 years ago
advanced-fetch v3.1.2
advanced-fetch
A version of node-fetch with more convenient functionality.
Installation
npm install advanced-fetchUsage
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:
queryfor GET query parameters, internally serialized using querystringformfor the body of aContent-Type: application/x-www-form-urlencodedrequest, internally serialized using URLSearchParamsformDatafor the body of aContent-Type: multipart/form-datarequest, internally serialized using form-datajsonfor the body of aContent-Type: application/jsonrequest, internally serialized usingJSON.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