status-codes
Version:
Return HTTP Status Codes with name and message
83 lines (53 loc) • 1.68 kB
Markdown
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
Small module to return all known HTTP status with a name and brief description.
```bash
$ npm install status-codes --save
```
All codes from this [Wiki HTTP Status Codes](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
```javascript
var statusCodes = require('status-codes');
statusCodes[404];
/**
Returns:
{
"status": 404,
"name": "Not Found",
"message": "The server has not found anything matching the Request-URI."
}
**/
// OR use a get method that has a fallback to a code 400 if it doesn't find a valid code
statusCodes.get(536727);
/**
Returns:
{
"status": 400,
"name": "Bad Request",
"message": "The server cannot or will not process the request."
}
**/
```
Can retrive HTTP status by name too:
```javascript
statusCodes.NOT_FOUND;
/**
Returns:
{
"status": 404,
"name": "Not Found",
"message": "The server has not found anything matching the Request-URI."
}
**/
```
[]: https://img.shields.io/npm/v/status-codes.svg?style=flat
[]: https://npmjs.org/package/status-codes
[]: https://img.shields.io/npm/dm/status-codes.svg?style=flat
[]: https://npmjs.org/package/status-codes
[]: https://img.shields.io/travis/strongloop/status-codes.svg?style=flat
[]: https://travis-ci.org/strongloop/status-codes
[]: https://img.shields.io/coveralls/strongloop/status-codes?style=flat
[]: https://coveralls.io/r/strongloop/status-codes?branch=master