HTTP Status Identifier
Purpose
A simple Node JS client that returns an HTTP Status, wrapped in a Promise, given either a status code (i.e 200
) or the status name (i.e I'm a teapot
).
It also returns an HTTP Status Family (INFORMATIONAL
or 1xx
, SUCCESS
or 2xx
, REDIRECTION
or 3xx
, CLIENT ERROR
or 4xx
, SERVER ERROR
or 5xx
) given a status family name or a specific HTTP Status.
Installation
Install via NPM.
npm install http-status-identifier
API
HTTP Statuses
To retrieve HTTP statuses use the identifyStatus
method.
The identifyStatus
method expects either
- an HTTP status code, represented as a
string
or anumber
- an HTTP status name, represented as a
string
The returned HttpStatus
object contains the following fields:
name
: Astring
which represents the name for the HTTP statuscode
: Anumber
which represents the code for the HTTP statusdescription
: Astring
that provides a brief overview of the HTTP statussupplementaryInformation
: Astring
that provides additional information for the HTTP status. This field may be empty where additional information is not necessary.documentationUrl
: Astring
that represents the URL where official documentation for the HTTP status is found. This is often a URL to RFC documentation.
Example
; // Returns HttpStatus.OKconst okHttpStatus = ; // Returns HttpStatus.IM_A_TEAPOTconst imATeapotHttpStatus = ; // Returns HttpStatus.BAD_REQUESTconst badRequestHttpStatus = ;
HTTP Status Families
To retrieve the HTTP Family for a given status use the identifyFamily
method.
The identifyFamily
method expects either
- an HTTP status code, represented as a
string
or anumber
- an HTTP status name, represented as a
string
Example
; // Returns HttpStatusFamily.SUCCESSconst successFamily = ; // Returns HttpStatusFamily.SUCCESSconst successFamilyAgain = ;