1.0.1 • Published 6 years ago

@shout-sdk/http-request v1.0.1

Weekly downloads
-
License
-
Repository
-
Last release
6 years ago

@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);