Package Exports
- @superhero/request
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@superhero/request) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Request
Licence: MIT
A wrapper for the http and https modules request function. I put this together to be able to simplify my api requests..
Install
npm install @superhero/request
...or just set the dependency in your package.json file:
{
"dependencies":
{
"@superhero/request": "*"
}
}Example
const
Request = require('@superhero/request'),
request = new Request();
request.post('example.com/foobar').then((result) => console.log(result.status, result.headers, result.data));
request.post({url:'https://example.com/foobar', data: {foo:'bar',baz:'qux'}}).then(console.log);Options
Options for the constructor.
{
// if true, some output for debugging is logged to the console
debug: false,
// this url will be used to resolve any provided url in the fetch call
url: '',
// headers that will be used in every request
headers: {},
// timeout
timeout: 30e3
}Options for each request
{
// the url to make the request to, relative paths will be resolved against
// the provided url in the constructor
url: '',
// an object map of the data to send with the request
data: undefined,
// an object map of headers to send with the request
headers: {},
// timeout, inherit from setting in the constructor
timeout: ?
}