http-status-codes
Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.
Last updated 4 years ago by prettymuchbryce .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install http-status-codes 
SYNC missed versions from official npm registry.

http-status-codes

Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.

All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), RFC2518 (WebDAV), RFC6585 (Additional HTTP Status Codes), and RFC7538 (Permanent Redirect) are supported.

TypeScript or JavaScript. Completely library agnostic. No dependencies.

Installation

npm install http-status-codes --save

Usage (express 4.x)

import { StatusCodes, ReasonPhrases, getReasonPhrase, getStatusCode } from 'http-status-codes';

response
	.status(StatusCodes.OK)
	.send(ReasonPhrases.OK);

response
	.status(StatusCodes.INTERNAL_SERVER_ERROR)
	.send({
		error: getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR)
	});

response
	.status(getStatusCode('Internal Server Error'))
	.send({
		error: 'Internal Server Error'
	});

Codes

Code Constant Reason Phrase
100 CONTINUE Continue
101 SWITCHING_PROTOCOLS Switching Protocols
102 PROCESSING Processing
200 OK OK
201 CREATED Created
202 ACCEPTED Accepted
203 NON_AUTHORITATIVE_INFORMATION Non Authoritative Information
204 NO_CONTENT No Content
205 RESET_CONTENT Reset Content
206 PARTIAL_CONTENT Partial Content
207 MULTI_STATUS Multi-Status
300 MULTIPLE_CHOICES Multiple Choices
301 MOVED_PERMANENTLY Moved Permanently
302 MOVED_TEMPORARILY Moved Temporarily
303 SEE_OTHER See Other
304 NOT_MODIFIED Not Modified
305 USE_PROXY Use Proxy
307 TEMPORARY_REDIRECT Temporary Redirect
308 PERMANENT_REDIRECT Permanent Redirect
400 BAD_REQUEST Bad Request
401 UNAUTHORIZED Unauthorized
402 PAYMENT_REQUIRED Payment Required
403 FORBIDDEN Forbidden
404 NOT_FOUND Not Found
405 METHOD_NOT_ALLOWED Method Not Allowed
406 NOT_ACCEPTABLE Not Acceptable
407 PROXY_AUTHENTICATION_REQUIRED Proxy Authentication Required
408 REQUEST_TIMEOUT Request Timeout
409 CONFLICT Conflict
410 GONE Gone
411 LENGTH_REQUIRED Length Required
412 PRECONDITION_FAILED Precondition Failed
413 REQUEST_TOO_LONG Request Entity Too Large
414 REQUEST_URI_TOO_LONG Request-URI Too Long
415 UNSUPPORTED_MEDIA_TYPE Unsupported Media Type
416 REQUESTED_RANGE_NOT_SATISFIABLE Requested Range Not Satisfiable
417 EXPECTATION_FAILED Expectation Failed
418 IM_A_TEAPOT I'm a teapot
419 INSUFFICIENT_SPACE_ON_RESOURCE Insufficient Space on Resource
420 METHOD_FAILURE Method Failure
422 UNPROCESSABLE_ENTITY Unprocessable Entity
423 LOCKED Locked
424 FAILED_DEPENDENCY Failed Dependency
428 PRECONDITION_REQUIRED Precondition Required
429 TOO_MANY_REQUESTS Too Many Requests
431 REQUEST_HEADER_FIELDS_TOO_LARGE Request Header Fields Too Large
500 INTERNAL_SERVER_ERROR Server Error
501 NOT_IMPLEMENTED Not Implemented
502 BAD_GATEWAY Bad Gateway
503 SERVICE_UNAVAILABLE Service Unavailable
504 GATEWAY_TIMEOUT Gateway Timeout
505 HTTP_VERSION_NOT_SUPPORTED HTTP Version Not Supported
507 INSUFFICIENT_STORAGE Insufficient Storage
511 NETWORK_AUTHENTICATION_REQUIRED Network Authentication Required

Migrating from v1.x.x

v2 is backwards compatible with v1, but if you are migrating from http-status-codes v1 to v2, there are a couple of changes that are recommended.

getStatusText renamed getReasonPhrase

To fix this, simply rename getStatusText() to getReasonPhrase(). The function is otherwise the same as it was before.

bad

getStatusText(200);

good

getReasonPhrase(200);

No wildcard imports

We're moving away from wildcard imports in favor of selective imports.

bad

import * as HttpStatus from 'http-status-codes';

good

import { StatusCodes } from 'http-status-codes';

These changes are optional now, but may be required in a future major version so please consider making them now.

Proposing a new status code

If you'd like to propose a new status code, feel free to update "codes.json" with the necessary information and open a pull request. No need to modify source code or even this README. The update-codes script will handle this all for you.

In general, we try to include only codes that have an official RFC and have been approved, however exceptions will be made if the code is already in widespread use in the wild.

Steps to build and publish

npm run update-codes
npm run test
npm run build
npm version [major | minor | patch]
npm run publish

Current Tags

  • 2.1.5-beta.1                                ...           beta (4 years ago)
  • 2.3.0                                ...           latest (a year ago)

40 Versions

  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           3 years ago
  • 2.1.5-beta.1                                ...           4 years ago
  • 2.1.5-beta.0                                ...           4 years ago
  • 2.1.4                                ...           4 years ago
  • 2.1.4-beta.5                                ...           4 years ago
  • 2.1.4-beta.4                                ...           4 years ago
  • 2.1.4-beta.3                                ...           4 years ago
  • 2.1.4-beta.2                                ...           4 years ago
  • 2.1.4-beta.1                                ...           4 years ago
  • 2.1.4-beta.0                                ...           4 years ago
  • 2.1.3                                ...           4 years ago
  • 2.1.3-beta.0                                ...           4 years ago
  • 2.1.2                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 2.0.0-beta.9                                ...           4 years ago
  • 2.0.0-beta.8                                ...           4 years ago
  • 2.0.0-beta.7                                ...           4 years ago
  • 2.0.0-beta.6                                ...           4 years ago
  • 2.0.0-beta.5                                ...           4 years ago
  • 2.0.0-beta.4                                ...           4 years ago
  • 2.0.0-beta.3                                ...           4 years ago
  • 2.0.0-beta.2                                ...           4 years ago
  • 2.0.0-beta.1                                ...           4 years ago
  • 2.0.0-beta.0                                ...           4 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.6                                ...           8 years ago
  • 1.0.6                                ...           9 years ago
  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE