0
# HTTP Status
1
2
HTTP Status provides a comprehensive utility library for interacting with HTTP status codes in Node.js applications. It offers both human-readable names and numeric codes for all standard HTTP status codes defined in the IANA HTTP Status Code Registry, plus the popular 418 'I'm a teapot' code. The library supports accessing status information through multiple patterns and includes extra status codes from popular web servers.
3
4
## Package Information
5
6
- **Package Name**: http-status
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install http-status`
10
11
## Core Imports
12
13
```typescript
14
import status from "http-status";
15
import { status } from "http-status";
16
import type { HttpStatus } from "http-status";
17
```
18
19
For CommonJS:
20
21
```javascript
22
const { status } = require("http-status");
23
const { default: status } = require("http-status");
24
```
25
26
**Note:** The package supports both ESM and CommonJS through dual exports defined in package.json. All import patterns are supported through the configured export paths.
27
28
## Basic Usage
29
30
```typescript
31
import status from "http-status";
32
33
// Get status name from code
34
console.log(status[200]); // "OK"
35
console.log(status[404]); // "Not Found"
36
37
// Get status code from constant
38
console.log(status.OK); // 200
39
console.log(status.NOT_FOUND); // 404
40
41
// Get detailed information
42
console.log(status["200_NAME"]); // "OK"
43
console.log(status["200_MESSAGE"]); // "Standard response for successful HTTP requests."
44
console.log(status["200_CLASS"]); // "2xx"
45
46
// Work with status classes
47
console.log(status.classes.SUCCESSFUL); // "2xx"
48
console.log(status.classes["2xx"]); // "Successful"
49
50
// Access extra status codes
51
console.log(status.extra.nginx.NO_RESPONSE); // 444
52
console.log(status.extra.cloudflare[520]); // "Unknown Error"
53
```
54
55
## Architecture
56
57
HTTP Status is organized around several key components:
58
59
- **Main Status Object**: Complete collection of all standard HTTP status codes with multiple access patterns
60
- **Status Classes**: Classification system grouping status codes by first digit (1xx-5xx)
61
- **Extra Status Codes**: Additional codes from popular web servers (NGINX, IIS, Cloudflare) and unofficial codes
62
- **Specialty Modules**: Pre-merged modules combining standard codes with specific server codes
63
- **TypeScript Integration**: Full type definitions for all status objects and access patterns
64
65
## Capabilities
66
67
### Standard HTTP Status Codes
68
69
Core HTTP status codes (1xx-5xx) with multiple access patterns including numeric lookup, constant names, and detailed information.
70
71
```typescript { .api }
72
interface StatusObject {
73
// Numeric keys return status names
74
[code: number]: string;
75
76
// Named constants return status codes
77
[name: string]: number | string;
78
79
// Information accessors
80
[key: `${number}_NAME`]: string;
81
[key: `${number}_MESSAGE`]: string;
82
[key: `${number}_CLASS`]: string;
83
}
84
```
85
86
[Standard Status Codes](./standard-codes.md)
87
88
### Status Code Classes
89
90
Classification system that groups status codes by their first digit, providing semantic meaning and class information.
91
92
```typescript { .api }
93
interface StatusClasses {
94
// Class identifiers
95
"1xx": "Informational";
96
"2xx": "Successful";
97
"3xx": "Redirection";
98
"4xx": "Client Error";
99
"5xx": "Server Error";
100
101
// Named constants
102
INFORMATIONAL: "1xx";
103
SUCCESSFUL: "2xx";
104
REDIRECTION: "3xx";
105
CLIENT_ERROR: "4xx";
106
SERVER_ERROR: "5xx";
107
108
// Class names and messages
109
[key: `${string}xx_NAME`]: string;
110
[key: `${string}xx_MESSAGE`]: string;
111
}
112
```
113
114
[Status Classes](./status-classes.md)
115
116
### Extra Status Codes
117
118
Additional status codes from popular web servers and unofficial codes that extend the standard HTTP status code set.
119
120
```typescript { .api }
121
interface ExtraStatusCodes {
122
unofficial: StatusObject;
123
iis: StatusObject;
124
nginx: StatusObject;
125
cloudflare: StatusObject;
126
}
127
```
128
129
[Extra Status Codes](./extra-codes.md)
130
131
### Specialty Modules
132
133
Pre-configured modules that merge standard status codes with specific server status codes for convenience.
134
135
```typescript { .api }
136
// Available specialty imports
137
import status from "http-status/cloudflare";
138
import status from "http-status/nginx";
139
import status from "http-status/iis";
140
import status from "http-status/unofficial";
141
```
142
143
[Specialty Modules](./specialty-modules.md)
144
145
## Types
146
147
```typescript { .api }
148
// Main status object type
149
type HttpStatus = typeof status;
150
151
// Status classes type
152
type HttpStatusClasses = typeof status.classes;
153
154
// Extra status code types
155
type HttpStatusUnofficial = typeof status.extra.unofficial;
156
type HttpStatusIis = typeof status.extra.iis;
157
type HttpStatusNginx = typeof status.extra.nginx;
158
type HttpStatusCloudflare = typeof status.extra.cloudflare;
159
```