@shout-sdk/http-request

Shout HttpRequest helper class for reducing the amount of required boilerplate code when making HTTP requests with fetch.

Usage no npm install needed!

<script type="module">
  import shoutSdkHttpRequest from 'https://cdn.skypack.dev/@shout-sdk/http-request';
</script>

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@address.com"
});

// Both methods produce a request ready to pass straight into a fetch call

const getResponse = await fetch(getRequest);

const postResponse = await fetch(postRequest);