http-status-codes
Advanced tools
Comparing version 1.4.0 to 2.0.0-beta.0
{ | ||
"name": "http-status-codes", | ||
"version": "1.4.0", | ||
"version": "2.0.0-beta.0", | ||
"description": "Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"update-codes": "ts-node --project ./scripts/tsconfig.json ./scripts/update-codes", | ||
"build-ts": "tsc --project tsconfig-build.json", | ||
"build": "npm run build-ts", | ||
"lint": "eslint .", | ||
"test": "jest ./src" | ||
}, | ||
@@ -12,3 +16,3 @@ "repository": { | ||
}, | ||
"main": "./index.js", | ||
"main": "./build/index.js", | ||
"keywords": [ | ||
@@ -25,3 +29,18 @@ "node", | ||
"license": "MIT", | ||
"typings": "index.d.ts" | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/jest": "^26.0.10", | ||
"@types/markdown-table": "^2.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.9.0", | ||
"@typescript-eslint/parser": "^3.9.1", | ||
"eslint": "^7.7.0", | ||
"eslint-config-airbnb-typescript": "^9.0.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"fs-extra": "^9.0.1", | ||
"jest": "^26.4.0", | ||
"markdown-table": "^2.0.0", | ||
"ts-jest": "^26.2.0", | ||
"ts-morph": "^7.3.0", | ||
"typescript": "^3.9.7" | ||
} | ||
} |
199
README.md
@@ -7,3 +7,3 @@ # http-status-codes | ||
Completely library agnostic. No dependencies. | ||
TypeScript or JavaScript. Completely library agnostic. No dependencies. | ||
@@ -19,120 +19,135 @@ ## Installation | ||
```javascript | ||
var HttpStatus = require('http-status-codes'); | ||
import { StatusCodes, ReasonPhrases, getReasonPhrase, getStatusCode } from 'http-status-codes'; | ||
response | ||
.status(HttpStatus.OK) | ||
.send('ok'); | ||
.status(StatusCodes.OK) | ||
.send(ReasonPhrases.OK); | ||
response | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.status(StatusCodes.INTERNAL_SERVER_ERROR) | ||
.send({ | ||
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR) | ||
error: getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR) | ||
}); | ||
response | ||
.status(HttpStatus.getStatusCode('Server Error')) | ||
.status(getStatusCode('Internal Server Error')) | ||
.send({ | ||
error: 'Server Error' | ||
error: 'Internal Server Error' | ||
}); | ||
``` | ||
## Codes | ||
## Codes | ||
Constant | Code | Status Text | ||
------------------------------------|-------|----------------------------------- | ||
ACCEPTED | 202 | Accepted | ||
BAD_GATEWAY | 502 | Bad Gateway | ||
BAD_REQUEST | 400 | Bad Request | ||
CONFLICT | 409 | Conflict | ||
CONTINUE | 100 | Continue | ||
CREATED | 201 | Created | ||
EXPECTATION_FAILED | 417 | Expectation Failed | ||
FAILED_DEPENDENCY | 424 | Failed Dependency | ||
FORBIDDEN | 403 | Forbidden | ||
GATEWAY_TIMEOUT | 504 | Gateway Timeout | ||
GONE | 410 | Gone | ||
HTTP_VERSION_NOT_SUPPORTED | 505 | HTTP Version Not Supported | ||
IM_A_TEAPOT | 418 | I'm a teapot | ||
INSUFFICIENT_SPACE_ON_RESOURCE | 419 | Insufficient Space on Resource | ||
INSUFFICIENT_STORAGE | 507 | Insufficient Storage | ||
INTERNAL_SERVER_ERROR | 500 | Server Error | ||
LENGTH_REQUIRED | 411 | Length Required | ||
LOCKED | 423 | Locked | ||
METHOD_FAILURE | 420 | Method Failure | ||
METHOD_NOT_ALLOWED | 405 | Method Not Allowed | ||
MOVED_PERMANENTLY | 301 | Moved Permanently | ||
MOVED_TEMPORARILY | 302 | Moved Temporarily | ||
MULTI_STATUS | 207 | Multi-Status | ||
MULTIPLE_CHOICES | 300 | Multiple Choices | ||
NETWORK_AUTHENTICATION_REQUIRED | 511 | Network Authentication Required | ||
NO_CONTENT | 204 | No Content | ||
NON_AUTHORITATIVE_INFORMATION | 203 | Non Authoritative Information | ||
NOT_ACCEPTABLE | 406 | Not Acceptable | ||
NOT_FOUND | 404 | Not Found | ||
NOT_IMPLEMENTED | 501 | Not Implemented | ||
NOT_MODIFIED | 304 | Not Modified | ||
OK | 200 | OK | ||
PARTIAL_CONTENT | 206 | Partial Content | ||
PAYMENT_REQUIRED | 402 | Payment Required | ||
PERMANENT_REDIRECT | 308 | Permanent Redirect | ||
PRECONDITION_FAILED | 412 | Precondition Failed | ||
PRECONDITION_REQUIRED | 428 | Precondition Required | ||
PROCESSING | 102 | Processing | ||
PROXY_AUTHENTICATION_REQUIRED | 407 | Proxy Authentication Required | ||
REQUEST_HEADER_FIELDS_TOO_LARGE | 431 | Request Header Fields Too Large | ||
REQUEST_TIMEOUT | 408 | Request Timeout | ||
REQUEST_TOO_LONG | 413 | Request Entity Too Large | ||
REQUEST_URI_TOO_LONG | 414 | Request-URI Too Long | ||
REQUESTED_RANGE_NOT_SATISFIABLE | 416 | Requested Range Not Satisfiable | ||
RESET_CONTENT | 205 | Reset Content | ||
SEE_OTHER | 303 | See Other | ||
SERVICE_UNAVAILABLE | 503 | Service Unavailable | ||
SWITCHING_PROTOCOLS | 101 | Switching Protocols | ||
TEMPORARY_REDIRECT | 307 | Temporary Redirect | ||
TOO_MANY_REQUESTS | 429 | Too Many Requests | ||
UNAUTHORIZED | 401 | Unauthorized | ||
UNPROCESSABLE_ENTITY | 422 | Unprocessable Entity | ||
UNSUPPORTED_MEDIA_TYPE | 415 | Unsupported Media Type | ||
USE_PROXY | 305 | Use Proxy | ||
| Code | Constant | Reason Phrase | | ||
| ---- | ------------------------------- | ------------------------------- | | ||
| 100 | CONTINUE | Continue | | ||
| 101 | SWITCHING_PROTOCOLS | Switching Protocols | | ||
| 102 | PROCESSING | Processing | | ||
| 200 | OK | OK | | ||
| 201 | CREATED | Created | | ||
| 202 | ACCEPTED | Accepted | | ||
| 203 | NON_AUTHORITATIVE_INFORMATION | Non Authoritative Information | | ||
| 204 | NO_CONTENT | No Content | | ||
| 205 | RESET_CONTENT | Reset Content | | ||
| 206 | PARTIAL_CONTENT | Partial Content | | ||
| 207 | MULTI_STATUS | Multi-Status | | ||
| 300 | MULTIPLE_CHOICES | Multiple Choices | | ||
| 301 | MOVED_PERMANENTLY | Moved Permanently | | ||
| 302 | MOVED_TEMPORARILY | Moved Temporarily | | ||
| 303 | SEE_OTHER | See Other | | ||
| 304 | NOT_MODIFIED | Not Modified | | ||
| 305 | USE_PROXY | Use Proxy | | ||
| 307 | TEMPORARY_REDIRECT | Temporary Redirect | | ||
| 308 | PERMANENT_REDIRECT | Permanent Redirect | | ||
| 400 | BAD_REQUEST | Bad Request | | ||
| 401 | UNAUTHORIZED | Unauthorized | | ||
| 402 | PAYMENT_REQUIRED | Payment Required | | ||
| 403 | FORBIDDEN | Forbidden | | ||
| 404 | NOT_FOUND | Not Found | | ||
| 405 | METHOD_NOT_ALLOWED | Method Not Allowed | | ||
| 406 | NOT_ACCEPTABLE | Not Acceptable | | ||
| 407 | PROXY_AUTHENTICATION_REQUIRED | Proxy Authentication Required | | ||
| 408 | REQUEST_TIMEOUT | Request Timeout | | ||
| 409 | CONFLICT | Conflict | | ||
| 410 | GONE | Gone | | ||
| 411 | LENGTH_REQUIRED | Length Required | | ||
| 412 | PRECONDITION_FAILED | Precondition Failed | | ||
| 413 | REQUEST_TOO_LONG | Request Entity Too Large | | ||
| 414 | REQUEST_URI_TOO_LONG | Request-URI Too Long | | ||
| 415 | UNSUPPORTED_MEDIA_TYPE | Unsupported Media Type | | ||
| 416 | REQUESTED_RANGE_NOT_SATISFIABLE | Requested Range Not Satisfiable | | ||
| 417 | EXPECTATION_FAILED | Expectation Failed | | ||
| 418 | IM_A_TEAPOT | I'm a teapot | | ||
| 419 | INSUFFICIENT_SPACE_ON_RESOURCE | Insufficient Space on Resource | | ||
| 420 | METHOD_FAILURE | Method Failure | | ||
| 422 | UNPROCESSABLE_ENTITY | Unprocessable Entity | | ||
| 423 | LOCKED | Locked | | ||
| 424 | FAILED_DEPENDENCY | Failed Dependency | | ||
| 428 | PRECONDITION_REQUIRED | Precondition Required | | ||
| 429 | TOO_MANY_REQUESTS | Too Many Requests | | ||
| 431 | REQUEST_HEADER_FIELDS_TOO_LARGE | Request Header Fields Too Large | | ||
| 500 | INTERNAL_SERVER_ERROR | Server Error | | ||
| 501 | NOT_IMPLEMENTED | Not Implemented | | ||
| 502 | BAD_GATEWAY | Bad Gateway | | ||
| 503 | SERVICE_UNAVAILABLE | Service Unavailable | | ||
| 504 | GATEWAY_TIMEOUT | Gateway Timeout | | ||
| 505 | HTTP_VERSION_NOT_SUPPORTED | HTTP Version Not Supported | | ||
| 507 | INSUFFICIENT_STORAGE | Insufficient Storage | | ||
| 511 | NETWORK_AUTHENTICATION_REQUIRED | Network Authentication Required | | ||
## TypeScript | ||
## Migrating from v1.x.x | ||
There is an included definition file that adds rules for use, comments, and links to official documentation. | ||
v2 is backwards compatible with v1, but if you are migrating from http-status-codes v1 to v2, there are a couple of changes that are recommended. | ||
### Usage | ||
### getStatusText renamed getReasonPhrase | ||
Option 1: Full import of package | ||
To fix this, simply rename `getStatusText()` to `getReasonPhrase()`. The function is otherwise the same as it was before. | ||
```typescript | ||
import * as HttpStatus from 'http-status-codes' | ||
**bad** ❌ | ||
response | ||
.status(HttpStatus.OK) | ||
.send('ok') | ||
``` | ||
getStatusText(200); | ||
``` | ||
response | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.send({ | ||
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR) | ||
}) | ||
**good** ✅ | ||
response | ||
.status(HttpStatus.getStatusCode('Server Error')) | ||
.send({ | ||
error: 'Server Error' | ||
}) | ||
``` | ||
getReasonPhrase(200); | ||
``` | ||
Option 2: Selective import | ||
### No wildcard imports | ||
We're moving away from wildcard imports in favor of selective imports. | ||
**bad** ❌ | ||
```typescript | ||
import { OK, getStatusText, getStatusCode } from 'http-status-codes' | ||
import * as HttpStatus from 'http-status-codes'; | ||
``` | ||
response | ||
.status(OK) | ||
.send(getStatusText(OK)) | ||
**good** ✅ | ||
response | ||
.status(getStatusCode('Server Error') | ||
.send('Server Error') | ||
```typescript | ||
import { StatusCodes } from 'http-status-codes'; | ||
``` | ||
These changes are __optional__ now, but may be required in a future major version so please consider making them now. | ||
## Proposing a new status code | ||
If you'd like to propose a new status code, feel free to update "codes.json" with the necessary | ||
information and open a pull request. No need to modify source code or even this README. | ||
The update-codes script will handle this all for you. | ||
In general, we try to include only codes that have an official RFC and have been approved, however | ||
exceptions will be made if the code is already in widespread use in the wild. | ||
## Steps to build and publish | ||
```shell | ||
npm run update-codes | ||
npm run test | ||
npm run build | ||
npm version [major | minor | patch] | ||
npm run publish | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
100910
17
1983
152
14
1