1.0.5 • Published 1 year ago

response-status-code v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

HTTP Status Codes for Express

npm version

This npm package provides a convenient way to use HTTP status codes with Express.js applications. It exports an object containing all standard HTTP status codes, making it easy to reference them in your Express routes.

Installation

You can install the package via npm:

bash

npm install response-status-code

Usage

Importing You can import the HTTP status codes object as http:

const http = require("response-status-code");

Or if you're using ES6 modules:

import http from "response-status-code";

Example

Here's how you can use it in an Express route:

const express = require("express");
const app = express();
const http = require("response-status-code");

app.get("/example", (req, res) => {
  // Send a 200 OK response
  res.status(http.statusOk).send("This is an example route");
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});

Available Status Codes

The package exports all standard HTTP status codes as properties of the http object. For example:

Status CodeDescriptionFunction Call
100Continuehttp.statusContinue
101Switching Protocolshttp.statusSwitchingProtocols
102Processinghttp.statusProcessing
103Early Hintshttp.statusEarlyHints
200OKhttp.statusOk
201Createdhttp.statusCreated
202Acceptedhttp.statusAccepted
203Non-Authoritative Informationhttp.statusNonAuthoritativeInformation
204No Contenthttp.statusNoContent
205Reset Contenthttp.statusResetContent
206Partial Contenthttp.statusPartialContent
207Multi-Statushttp.statusMultiStatus
208Already Reportedhttp.statusAlreadyReported
226IM Usedhttp.statusIMUsed
300Multiple Choiceshttp.statusMultipleChoices
301Moved Permanentlyhttp.statusMovedPermanently
302Foundhttp.statusFound
303See Otherhttp.statusSeeOther
304Not Modifiedhttp.statusNotModified
305Use Proxyhttp.statusUseProxy
307Temporary Redirecthttp.statusTemporaryRedirect
308Permanent Redirecthttp.statusPermanentRedirect
400Bad Requesthttp.statusBadRequest
401Unauthorizedhttp.statusUnauthorized
402Payment Requiredhttp.statusPaymentRequired
403Forbiddenhttp.statusForbidden
404Not Foundhttp.statusNotFound
405Method Not Allowedhttp.statusMethodNotAllowed
406Not Acceptablehttp.statusNotAcceptable
407Proxy Authentication Requiredhttp.statusProxyAuthenticationRequired
408Request Timeouthttp.statusRequestTimeout
409Conflicthttp.statusConflict
410Gonehttp.statusGone
411Length Requiredhttp.statusLengthRequired
412Precondition Failedhttp.statusPreconditionFailed
413Payload Too Largehttp.statusPayloadTooLarge
414URI Too Longhttp.statusURITooLong
415Unsupported Media Typehttp.statusUnsupportedMediaType
416Range Not Satisfiablehttp.statusRangeNotSatisfiable
417Expectation Failedhttp.statusExpectationFailed
418I'm a teapothttp.statusImATeapot
421Misdirected Requesthttp.statusMisdirectedRequest
422Unprocessable Entityhttp.statusUnprocessableEntity
423Lockedhttp.statusLocked
424Failed Dependencyhttp.statusFailedDependency
425Too Earlyhttp.statusTooEarly
426Upgrade Requiredhttp.statusUpgradeRequired
428Precondition Requiredhttp.statusPreconditionRequired
429Too Many Requestshttp.statusTooManyRequests
431Request Header Fields Too Largehttp.statusRequestHeaderFieldsTooLarge
451Unavailable For Legal Reasonshttp.statusUnavailableForLegalReasons
500Internal Server Errorhttp.statusInternalServerError
501Not Implementedhttp.statusNotImplemented
502Bad Gatewayhttp.statusBadGateway
503Service Unavailablehttp.statusServiceUnavailable
504Gateway Timeouthttp.statusGatewayTimeout

If you encounter any issues or would like to contribute to this package, feel free to open an issue or submit a pull request.

License

This package is open source and available under the MIT License.

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago