@temporal/node-fetch
v1.0.0
Published
Simple async/await based node fetch wrapper
Downloads
2
Readme
@temporal/node-fetch
Simple async
/await
based node-fetch wrapper.
Support
- Currently supports only
get
requests.
Installation
npm i -S @temporal/node-fetch
Usage
get(url, [options])
Makes a HTTP GET
request.
Arguments
url
(string): The URL to make a get request- (Optional)
options
(object): Custom options
Returns
Promise that resolves to a TemporalResponse object or rejects with a TemporalNodeFetchError
const { get } = require('@temporal/node-fetch');
await get(someURL);
Options
Options have the following defaults:
{
timeout: 6000, // same as the timeout option of `node-fetch`
headers: {}, // custom headers; `Accept: application/json` is already included
query: {} // query string parameters to be included in the url
errorName: 'TemporalNodeFetch' // custom error name
}
The query
parameters are stringified with the node's built-in querystring module.
TemporalResponse
This is a plain javascript object literal
{
status: 200, // the HTTP status from the `get` operation
data: {} // the json response data from the `get` operation
}
TemporalNodeFetchError
This error has the following attributes:
error.name = 'TemporalNodeFetchError'; // if `errorName` option is 'Test', then this becomes 'TestError'
error.message = '<the error message>';
error.status = 500; // HTTP error status from the `get` operation
// you can also read the regular `error.stack`