statusmate-http
v1.0.3
Published
A package that provides human-readable descriptions and helper methods for HTTP status codes.
Downloads
83
Maintainers
Readme
HTTP Status Code
A package that provides human-readable descriptions and helper methods for HTTP status codes.
Installation
$ npm install --save statusmate-http
or you can use yarn
$ yarn add statusmate-http
Import statusmate-http into your app
import {
getStatusDescription,
isServerError,
isClientError,
isSuccess,
isRedirection,
isInformational,
} from 'statusmate-http';
Get status description
You can retrieve the human-readable description of an HTTP status code using getStatusDescription
:
const description = getStatusDescription(404); //Not Found
console.log(description);
Check if Status Code is a Server Error
You can check if a status code indicates a server error using isServerError
:
const isError = isServerError(500); // true
console.log(isError);
Check if Status Code is a Client Error
Similarly, you can check if a status code is a client error using isClientError
:
const isError = isClientError(404); // true
console.log(isError);
Check if Status Code Indicates Success
To check if a status code indicates a successful response:
const isOk = isSuccess(200); // true
console.log(isOk);
Check if Status Code Indicates Redirection
To check if a status code indicates a redirection:
const isRedirect = isRedirection(302); // true
console.log(isRedirect);
Check if Status Code is Informational
You can check if a status code is informational:
const isInfo = isInformational(100); // true
console.log(isInfo);
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D