@shout-sdk/http-request
v1.0.1
Published
Shout HttpRequest helper class for reducing the amount of required boilerplate code when making HTTP requests with fetch.
Downloads
2
Readme
@shout-sdk/http-request
shout-http-request is a package to help reduce the amount of boilerplate code when making HTTP requests with fetch.
It contains sensible defaults and handles the conversion of any JavaScript object into a JSON string during POST requests.
Install
npm i @shout-sdk/http-request
Example Usage
// Import the class from the npm package
import { HttpRequest } from '@shout-sdk/http-request';
const getRequest = HttpRequest.get('http://google.com', {
'Accept': 'application/json'
});
const postRequest = HttpRequest.post('http://google.com', HttpRequest.DefaultPostHeaders, {
userId: 1000001,
email: "[email protected]"
});
// Both methods produce a request ready to pass straight into a fetch call
const getResponse = await fetch(getRequest);
const postResponse = await fetch(postRequest);