Skip to content

Commit fc24d8d

Browse files
committed
docs: rephrase readme and use esm for example
1 parent 967f617 commit fc24d8d

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ Utility to interact with HTTP status codes.
66

77
## Usage
88

9-
Once you require this module, you may call it with either an HTTP code or a message name. With an HTTP code, you will get the message name while with a message name you will get an HTTP code.
9+
Once you import or require this module, you may call it with either an HTTP code or a status name. With an HTTP code, you will get the status name while with a status name you will get an HTTP code or some complementary information.
10+
11+
For example, `status[418]` return `IM_A_TEAPOT` while `status.IM_A_TEAPOT` return `"I'm a teapot"` and `status.IM_A_TEAPOT_CODE` returns `418`.
1012

1113
The package is written in TypeScript and built for CommonJS and ESM.
1214

13-
### HTTP Status codes
15+
## HTTP Status codes
16+
17+
HTTP code names, information, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`.
1418

15-
HTTP code names, messages, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`.
19+
## Extra codes
1620

17-
Extra status code are also made available that are not defined in the IANA registry, but used by popular software. They are grouped by category. Specific properties are exported by `http-status` under the property `extra` followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside `http-status/lib/{category}`.
21+
Extra status code are also made available that are not defined in the IANA registry, but used by popular softwares. They are grouped by category. Specific properties are exported by `http-status` under the property `extra` followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside `http-status/lib/{category}`.
1822

1923
Available categories are:
2024

@@ -29,9 +33,11 @@ Available categories are:
2933
<dd>Cloudflare's reverse proxy service expands the 5xx error class to signal issues with the origin server.</dd>
3034
</dl>
3135

32-
### HTTP Status code classes
36+
They are accessible throught the `status.extra[category]` property. It is also possible to import one of the category with `import status from "http-status/<category>" or `const status = require("http-status/<category>")`. In the later case, all the categories properties are merge with the common HTTP statuses.
37+
38+
## HTTP Status code classes
3339

34-
In addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE`
40+
In addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE`.
3541

3642
## API
3743

@@ -95,7 +101,7 @@ For additional information, please refer to [original code](./src/index.litcoffe
95101
### Example usage
96102

97103
```javascript
98-
const status = require("http-status");
104+
import status from "http-status";
99105

100106
console.info(status.INTERNAL_SERVER_ERROR);
101107
// Output: 500
@@ -120,7 +126,7 @@ console.info(status[`${status.INTERNAL_SERVER_ERROR}_CLASS`]);
120126
### Example using `classes`
121127

122128
```javascript
123-
const status = require("http-status");
129+
import status from "http-status";
124130

125131
const responseCode = status.INTERNAL_SERVER_ERROR;
126132

@@ -151,20 +157,22 @@ switch (status[`${responseCode}_CLASS`]) {
151157

152158
```javascript
153159
// Accessing property from the NGINX category
154-
const status = require("http-status");
160+
import status from "http-status";
155161
console.info(status.extra.nginx.NO_RESPONSE);
162+
156163
// Accessing default HTTP status merged with NGINX status
157-
const status = require("http-status/lib/nginx");
164+
import status from "http-status/lib/nginx";
158165
console.info(status.IM_A_TEAPOT);
159166
console.info(status.NO_RESPONSE);
160167
```
161168

162169
### Example integrating Express
163170

164171
```javascript
165-
const express = require("express"),
166-
redis = require("redis"),
167-
status = require("http-status");
172+
import express from "express";
173+
import redis from "redis";
174+
import status from "http-status";
175+
168176
// New Express HTTP server
169177
const app = express.createServer();
170178
// Regster a route
@@ -189,7 +197,7 @@ app.listen(3000);
189197
- Paul Vollmer: <[email protected]>
190198
- James Barcellano: <https://github.com/ckeboss>
191199

192-
This package is developed by [Adaltas](https://www.adaltas.com).
200+
The project is sponsored by [Adaltas](https://www.adaltas.com) based in Paris, France. Adaltas offers support and consulting on distributed systems, big data and open source.
193201

194202
## Developers
195203

0 commit comments

Comments
 (0)