Socket
Socket
Sign inDemoInstall

http-status-codes

Package Overview
Dependencies
0
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    http-status-codes

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


Version published
Weekly downloads
1.6M
decreased by-11.41%
Maintainers
1
Install size
27.5 kB
Created
Weekly downloads
 

Package description

What is http-status-codes?

The http-status-codes npm package provides an easy-to-use collection of HTTP status codes and reason phrases, which are useful when writing server-side code. It helps developers to avoid hardcoding numeric status codes and instead use descriptive constants, improving code readability and maintainability.

What are http-status-codes's main functionalities?

Status Code Enumeration

Provides an enumeration of HTTP status codes, allowing developers to use descriptive constants instead of numeric codes.

const { StatusCodes } = require('http-status-codes');

console.log(StatusCodes.OK); // 200
console.log(StatusCodes.NOT_FOUND); // 404
console.log(StatusCodes.INTERNAL_SERVER_ERROR); // 500

Reason Phrase Lookup

Allows developers to get the standard reason phrase for a given HTTP status code.

const { getReasonPhrase } = require('http-status-codes');

console.log(getReasonPhrase(200)); // 'OK'
console.log(getReasonPhrase(404)); // 'Not Found'
console.log(getReasonPhrase(500)); // 'Internal Server Error'

Status Code Lookup

Enables developers to retrieve the numeric status code for a given reason phrase.

const { getStatusCode } = require('http-status-codes');

console.log(getStatusCode('OK')); // 200
console.log(getStatusCode('Not Found')); // 404
console.log(getStatusCode('Internal Server Error')); // 500

Other packages similar to http-status-codes

Readme

Source

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.

Completely library agnostic. No dependencies.

Installation

npm install http-status-codes --save

Usage (express 4.x)

var HttpStatus = require('http-status-codes');

response
	.status(HttpStatus.OK)
	.send('ok');

response
	.status(HttpStatus.INTERNAL_SERVER_ERROR)
	.send({
		error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
	});

Codes

ConstantCodeMessage
ACCEPTED202Accepted
BAD_GATEWAY502Bad Gateway
BAD_REQUEST400Bad Request
CONFLICT409Conflict
CONTINUE100Continue
CREATED201Created
EXPECTATION_FAILED417Expectation Failed
FAILED_DEPENDENCY424Failed Dependency
FORBIDDEN403Forbidden
GATEWAY_TIMEOUT504Gateway Timeout
GONE410Gone
HTTP_VERSION_NOT_SUPPORTED505HTTP Version Not Supported
INSUFFICIENT_SPACE_ON_RESOURCE419Insufficient Space on Resource
INSUFFICIENT_STORAGE507Insufficient Storage
INTERNAL_SERVER_ERROR500Server Error
LENGTH_REQUIRED411Length Required
LOCKED423Locked
METHOD_FAILURE420Method Failure
METHOD_NOT_ALLOWED405Method Not Allowed
MOVED_PERMANENTLY301Moved Permanently
MOVED_TEMPORARILY302Moved Temporarily
MULTI_STATUS207Multi-Status
MULTIPLE_CHOICES300Multiple Choices
NETWORK_AUTHENTICATION_REQUIRED511Network Authentication Required
NO_CONTENT204No Content
NON_AUTHORITATIVE_INFORMATION203Non Authoritative Information
NOT_ACCEPTABLE406Not Acceptable
NOT_FOUND404Not Found
NOT_IMPLEMENTED501Not Implemented
NOT_MODIFIED304Not Modified
OK200OK
PARTIAL_CONTENT206Partial Content
PAYMENT_REQUIRED402Payment Required
PERMANENT_REDIRECT308Permanent Redirect
PRECONDITION_FAILED412Precondition Failed
PRECONDITION_REQUIRED428Precondition Required
PROCESSING102Processing
PROXY_AUTHENTICATION_REQUIRED407Proxy Authentication Required
REQUEST_HEADER_FIELDS_TOO_LARGE431Request Header Fields Too Large
REQUEST_TIMEOUT408Request Timeout
REQUEST_TOO_LONG413Request Entity Too Large
REQUEST_URI_TOO_LONG414Request-URI Too Long
REQUESTED_RANGE_NOT_SATISFIABLE416Requested Range Not Satisfiable
RESET_CONTENT205Reset Content
SEE_OTHER303See Other
SERVICE_UNAVAILABLE503Service Unavailable
SWITCHING_PROTOCOLS101Switching Protocols
TEMPORARY_REDIRECT307Temporary Redirect
TOO_MANY_REQUESTS429Too Many Requests
UNAUTHORIZED401Unauthorized
UNPROCESSABLE_ENTITY422Unprocessable Entity
UNSUPPORTED_MEDIA_TYPE415Unsupported Media Type
USE_PROXY305Use Proxy

TypeScript

There is an included definition file that adds rules for use, comments, and links to official documentation.

Usage

Option 1: Full import of package

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

response
	.status(HttpStatus.OK)
	.send('ok')

response
	.status(HttpStatus.INTERNAL_SERVER_ERROR)
	.send({
		error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
	})

Option 2: Selective import

import { OK, getStatusText } from 'http-status-codes'

response
	.status(OK)
	.send(getStatusText(OK))

Keywords

FAQs

Last updated on 24 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc