1.1.0 • Published 6 months ago

http-status-string v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

http-status-string

A simple and lightweight NPM package that provides HTTP status codes as easily readable string keys. Instead of remembering numeric HTTP status codes, developers can use intuitive key names like CONTINUE_100, OK_200, NOT_FOUND_404, and INTERNAL_SERVER_ERROR_500 to improve code readability and maintainability.

Installation

Install the package via npm:

npm install http-status-string

or using yarn:

yarn add http-status-string

Usage

Import and use the package in your project:

const { HttpStatus } = require('http-status-string');

console.log(HttpStatus.OK_200); // 200
console.log(HttpStatus.NOT_FOUND_404); // 404
console.log(HttpStatus.INTERNAL_SERVER_ERROR_500); // 500

HTTP Status Codes

1xx: Informational Responses

Status CodeNameDescription
100CONTINUE_100The request has been received and the process is continuing.
101SWITCHING_PROTOCOLS_101The server is switching protocols as requested.
102PROCESSING_102The request is being processed but no response is available yet.
103EARLY_HINTS_103The server is sending hints before the final response.

2xx: Success Responses

Status CodeNameDescription
200OK_200The request was successful.
201CREATED_201The request was successful, and a new resource was created.
202ACCEPTED_202The request has been accepted for processing but is not completed.
203NON_AUTHORITATIVE_INFORMATION_203The request was successful but may be from another source.
204NO_CONTENT_204The request was successful, but there is no content to return.
205RESET_CONTENT_205The request was successful, and the client should reset the document view.
206PARTIAL_CONTENT_206The server is delivering only part of the resource due to a range header sent by the client.
208ALREADY_REPORTED_208The resource was already reported earlier.
226IM_USED_226The server has completed a GET request using instance manipulations.

3xx: Redirection Responses

Status CodeNameDescription
300MULTIPLE_CHOICES_300The requested resource has multiple choices.
301MOVED_PERMANENTLY_301The requested resource has moved permanently.
302FOUND_302The requested resource is found but temporarily moved.
303SEE_OTHER_303The response can be found at another URI using a GET method.
304NOT_MODIFIED_304The resource has not been modified since the last request.
307TEMPORARY_REDIRECT_307The request should be repeated at another URI.
308PERMANENT_REDIRECT_308The request should be repeated at another URI permanently.

4xx: Client Errors

Status CodeNameDescription
400BAD_REQUEST_400The request could not be understood due to malformed syntax.
401UNAUTHORIZED_401Authentication is required to access this resource.
402PAYMENT_REQUIRED_402Payment is required to access this resource.
403FORBIDDEN_403The server understands the request but refuses to authorize it.
404NOT_FOUND_404The requested resource could not be found.
405METHOD_NOT_ALLOWED_405The request method is not supported for the resource.
406NOT_ACCEPTABLE_406The requested resource is not acceptable according to headers.
408REQUEST_TIMEOUT_408The server timed out waiting for the request.
409CONFLICT_409The request conflicts with the current state of the resource.
410GONE_410The resource is no longer available and has been removed.
411LENGTH_REQUIRED_411The request requires a valid Content-Length header.
412PRECONDITION_FAILED_412The request failed precondition checks.
413PAYLOAD_TOO_LARGE_413The request payload is too large.
414URI_TOO_LONG_414The requested URI is too long.
415UNSUPPORTED_MEDIA_TYPE_415The media type of the request is unsupported.
416RANGE_NOT_SATISFIABLE_416The requested range is invalid.
417EXPECTATION_FAILED_417The expectation in the request headers could not be met.
429TOO_MANY_REQUESTS_429The user has sent too many requests in a given time.

5xx: Server Errors

Status CodeNameDescription
500INTERNAL_SERVER_ERROR_500The server encountered an unexpected condition.
501NOT_IMPLEMENTED_501The request method is not supported by the server.
502BAD_GATEWAY_502The server received an invalid response from an upstream server.
503SERVICE_UNAVAILABLE_503The server is temporarily unable to handle the request.
504GATEWAY_TIMEOUT_504The server did not receive a timely response from an upstream server.
505HTTP_VERSION_NOT_SUPPORTED_505The HTTP version used in the request is not supported.
508LOOP_DETECTED_508The server detected an infinite loop while processing the request.

Non-Major Status Codes

These status codes are used less frequently but still hold importance in specific scenarios.

Status CodeNameDescription
418IM_A_TEAPOT_418The server refuses to brew coffee because it is a teapot.
422UNPROCESSABLE_ENTITY_422The request was well-formed but could not be processed.
451UNAVAILABLE_FOR_LEGAL_REASONS_451The resource is unavailable due to legal reasons.

About the Author

This package is developed and maintained by Seiam Al Mahmud. He is a passionate web developer experienced in JavaScript, Node.js, React, and backend technologies. You can find more about his work on his GitHub profile:

GitHub: SeiamAlMahmud

Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License.

1.1.0

6 months ago

1.0.0

6 months ago