https://github.com/jaebradley/http-status-identifier
🤔 What's my HTTP status?
https://github.com/jaebradley/http-status-identifier
http nodejs npm npm-package
Last synced: about 1 year ago
JSON representation
🤔 What's my HTTP status?
- Host: GitHub
- URL: https://github.com/jaebradley/http-status-identifier
- Owner: jaebradley
- License: mit
- Created: 2017-04-07T01:17:57.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T09:35:34.000Z (almost 3 years ago)
- Last Synced: 2025-03-03T17:17:46.429Z (about 1 year ago)
- Topics: http, nodejs, npm, npm-package
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/http-status-identifier
- Size: 4.79 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Status Identifier
[](https://greenkeeper.io/)
[](https://travis-ci.org/jaebradley/http-status-identifier)
[](https://codecov.io/gh/jaebradley/http-status-identifier)
[](https://badge.fury.io/js/http-status-identifier)
[](https://www.npmjs.com/package/http-status-identifier)
## Purpose
A simple Node JS client that returns an [HTTP Status](https://github.com/jaebradley/http-status-identifier/blob/master/src/data/HttpStatus.js), 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](https://github.com/jaebradley/http-status-identifier/blob/master/src/data/HttpStatusFamily.js) (`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](https://www.npmjs.com/package/http-status-identifier).
```
npm install http-status-identifier
```
## API
### HTTP Statuses
To retrieve HTTP statuses use the `identifyStatus` method.
The `identifyStatus` method expects either
1. an HTTP status code, represented as a `string` or a `number`
2. an HTTP status name, represented as a `string`
The returned [`HttpStatus`](https://github.com/jaebradley/http-status-code-definition-identifier/blob/master/src/data/HttpStatus.js) object contains the following fields:
* `name`: A `string` which represents the name for the HTTP status
* `code`: A `number` which represents the code for the HTTP status
* `description`: A `string` that provides a brief overview of the HTTP status
* `supplementaryInformation`: A `string` that provides additional information for the HTTP status. This field may be empty where additional information is not necessary.
* `documentationUrl`: A `string` that represents the URL where official documentation for the HTTP status is found. This is often a URL to RFC documentation.
#### Example
```javascript
import { identifyStatus } from 'http-status-identifier';
// Returns HttpStatus.OK
const okHttpStatus = identifyStatus(200);
// Returns HttpStatus.IM_A_TEAPOT
const imATeapotHttpStatus = identifyStatus("I'm a teapot");
// Returns HttpStatus.BAD_REQUEST
const badRequestHttpStatus = identifyStatus('400');
```
### HTTP Status Families
To retrieve the HTTP Family for a given status use the `identifyFamily` method.
The `identifyFamily` method expects either
1. an HTTP status code, represented as a `string` or a `number`
2. an HTTP status name, represented as a `string`
#### Example
```javascript
import { identifyFamily } from 'http-status-identifier';
// Returns HttpStatusFamily.SUCCESS
const successFamily = identifyFamily('sUcCesS');
// Returns HttpStatusFamily.SUCCESS
const successFamilyAgain = identifyFamily(200);
```