2.0.1 • Published 8 months ago

http-status-typed v2.0.1

Weekly downloads
96
License
MIT
Repository
github
Last release
8 months ago

http-status-typed

This is http-status-codes but the status codes are wrapped in an enum so you can have a Typescript type for the status codes. The size of the package is also incredibly small (4kb uncompressed after tree shaking).

Version 1.0.1 significantly reduces the size of the package. Good for browsers now.

Version 1.0.2 supports both CommonJS and ES Modules but doubles the size of the package (since we're now publishing two files).

Version 2.0.0 only supports ES Modules.

Version 2.0.1 removes unneeded artifacts and reduces the size of the package.

Installation

npm install http-status-typed --save

Usage (Typescript)

import HttpStatusCode from 'http-status-typed';

interface ApiResponse {
    status: HttpStatusCode;
    response: object;
}

function handleResponse(): ApiResponse {
    return {
        status: HttpStatusCode.OK;
        response: {
            body: "😎"
        };
    }
}

Codes

ConstantCodeStatus Text
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
IM_A_TEAPOT418I'm a teapot
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