1.0.3 • Published 3 years ago

reusable-rest-header v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Reusable REST Headers

Jest build status Contributions welcome

A reusable rest header object which can be used in your JavaScript code to create headers using builder pattern.

To generate the following output,

{
  'Cache-Control': 'no-store no-cache',
  'api-version': 1,
  'Content-Type': 'application/json',
  Accept: 'application/json',
  Authorization: 'Bearer 0b195ce6-09a1-4dc7-a4eb-256535065846'
}

Use the below code:

new RESTHeader(1).addBearerAuth(uuidv4()).build();

Usage

Install package to your project using the following command:

npm i reusable-rest-header

Once installed you can import the RESTHeader

const RESTHeader = require('reusable-rest-header/RESTHeader');

Use this defined const as:

new RESTHeader(1).addBearerAuth(uuidv4()).build();

Available static methods

To speed up development, use available static methods:

bearerAuthOnly

Using: RESTHeader.bearerAuthOnly(random_token);

{
  'Cache-Control': 'no-store no-cache',
  'Content-Type': 'application/json',
  Accept: 'application/json',
  Authorization: 'Bearer 187addda-b57b-4642-87dc-24a6a155f172'
}

bearerAuthWithApiVersion

Using: RESTHeader.bearerAuthWithApiVersion(1, random_token);

{
  'Cache-Control': 'no-store no-cache',
  'api-version': 1,
  'Content-Type': 'application/json',
  Accept: 'application/json',
  Authorization: 'Bearer 1305da60-434e-4edd-a9c5-a5794d97a870'
}

defaultHeaders

Using: RESTHeader.defaultHeaders();

{
  'Cache-Control': 'no-store no-cache',
  'Content-Type': 'application/json',
  Accept: 'application/json',
}

Available methods

addAccept(acceptType = "application/json")

addAcceptScim()

addBasicAuth(credentials)

addBearerAuth(accessToken)

addPlainAuth(accessToken)

addContentType(contentType = "application/json")

addFormContentType()

addProductKey(productKey)

addETag(etag)

addSignature(sharedKey, secretKey)

addCustomHeader(customheaderValue)

Contributions are welcome

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago