@overseers/simply-fetch
v1.1.0
Published
Fetch wrapper to simplify the interface, the output, and bring back some of the comforts of request.
Downloads
4
Readme
@overseers/simply-fetch
A node-fetch wrapper to simplify the interface, the output, and bring back some of the comforts of request.
npm i @overseers/simply-fetch
Usage
const { fetch } = require('@overseers/simply-fetch');
fetch({ url: 'https://sv443.net/jokeapi/v2/joke/Any' }).then((response) => {
console.log('RESPONSE: ', response);
}).catch((err) => {
console.log('ERROR: ', err);
});
Input
Request Object:
url
: (required) route to the requested resourcemethod
: (optional) method to utilize for request- Default: 'GET'
headers
: (optional) headers to be utilized in the requestqs
: (optional) an object representing the query string- example of use:
fetch({ url: 'https://someurl/here?key=value&key1=value1' }); // VS fetch({ url: 'https://someurl/here', qs: { key: value, key1: value1 });
- example of use with an array of a key:
fetch({ url: 'https://someurl/here?key=value&key=value1&key1=value2' }); // VS fetch({ url: 'https://someurl/here', qs: { key: [value, value1], key1: value2 });
- example of use:
body
: (optional) a payload to be sent as the body of a requestformData
: (optional) can be used for file-uploads and other multi-part requests- form-data is utilized to accommodate for this functionality
agent
: (optional) an object to be passed to Node to be utilized during the request, details can be found here- example:
const https = require('https'); const agent = new https.Agent({ rejectUnauthorized: false }); fetch({ url: 'https://someurl/here', agent });
- example:
Output
Response Object:
status
: the status number sent back from the requestheaders
: the headers from the responsebody
: the response being sent back