0.1.0 • Published 3 years ago

boomerang-http v0.1.0

Weekly downloads
36
License
Open BSV License
Repository
github
Last release
3 years ago

boomerang-http

Simplified wrapper around the fetch API

Name and Meaning

You throw the boomerang through cyberspace at a URL. It comes back and hits you in the face, ideally with the data you want.

Usage

import boomerang from 'boomerang-http'

const data = await boomerang(
  'POST',
  'https://example.com',
  {
    para: 'meter'
  },
  {
    hea: 'der'
  }
)

API

The package exports a single function, boomerang, which requests your data.

boomerang(HTTPMethod, URL, requestPayload, headers) => response

This function will parse your data into the correct format for the HTTP method used, send the request and parse the response into either a JSON object or a string.

Parameters

NameOptionalDescription
methodNoThe HTTP method to use for the request
URLNoThe URL to request
paramsYesRequest parameters. For GET, these will be your query string parameters. For POST, this will be sent as the JSON request body
headersYesAny additional headers to include with the request

Return Value

The function will return a Promise for either a JavaScript object (if the response was JSON), or a string value.

Throws

This function will throw native errors if they occur. No custom errors are defined. This is a wrapper for the fetch API. Please consult the documentation for more information.

License

The license for the code in this repository is the Open BSV License.