https://github.com/shresht7/http-status-codes
TypeScript enum and reference for HTTP status codes.
https://github.com/shresht7/http-status-codes
http-status-codes
Last synced: 2 months ago
JSON representation
TypeScript enum and reference for HTTP status codes.
- Host: GitHub
- URL: https://github.com/shresht7/http-status-codes
- Owner: Shresht7
- License: mit
- Created: 2022-01-20T08:17:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-21T20:39:38.000Z (4 months ago)
- Last Synced: 2025-01-27T09:09:39.613Z (4 months ago)
- Topics: http-status-codes
- Language: TypeScript
- Homepage:
- Size: 114 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
HTTP Status Codes
๐ง Work in Progress ๐ง
## ๐ Usage
```ts
import { Status, Code } from 'http-status-code'Status.INFORMATION.PROCESSING // 102
Status.SUCCESS.OK // 200
Status.CLIENT_ERROR[404] // NOT_FOUNDCode.BAD_GATEWAY // 502
Code[200] // OK
```### `Status`
| Status Type | Series | Description |
| --------------------- | ------ | --------------------------------------------------------------- |
| `Status.INFORMATION` | `1xx` | The request was received and understood, continuing process |
| `Status.SUCCESS` | `2xx` | Request was received, understood, and accepted |
| `Status.REDIRECT` | `3xx` | Additional action requested from client. Mainly URL Redirection |
| `Status.CLIENT_ERROR` | `4xx` | Request cannot be fulfilled due to a client side error |
| `Status.SERVER_ERROR` | `5xx` | Request cannot be fulfilled due to a server side error |```ts
Status.INFORMATION.PROCESSING // 102
Status.SUCCESS.OK // 200
Status.CLIENT_ERROR[404] // NOT_FOUND
```### `Code`
```ts
Code.SWITCHING_PROTOCOLS // 101
Code.CREATED // 201
Code.BAD_REQUEST // 400
Code[301] // MOVED_PERMANENTLY
```### `StatusText`
```ts
import { Status, Code, StatusText } from 'http-status-code'StatusText(Code.CONTINUE) // Continue
StatusText(Status.INFORMATION.SWITCHING_PROTOCOLS) // Switching Protocols
StatusText(404) // Not Found
````StatusText` can be given a custom formatter to customize the output string.
```ts
StatusText(Status.CLIENT_ERROR.NOT_FOUND, (text: string) => {
return `[${Code[text]} - ${text}]: Nothing to see here!`
})
// [404 - NOT_FOUND]: Nothing to see here!
```### `Checks`
`isStatus` | `isInformation` | `isSuccess` | `isRedirect` | `isClientError` | `isServerError` | `isError`
```ts
import {
Code,
Status,
isStatus,
isInformation,
isSuccess,
isRedirect,
isClientError,
isServerError
} from 'http-status-code'isStatus(Status.REDIRECT.MOVED_PERMANENTLY) // true
isStatus(Code.BAD_REQUEST) // true
isStatus(502) // true
isStatus(987) // falseisInformation(Status.INFORMATION.SWITCHING_PROTOCOLS) // true
isInformation(Code.INTERNAL_SERVER_ERROR) // falseisSuccess(200) // true
isSuccess(Code.NOT_FOUND) // falseisRedirect(301) // true
isClientError(404) // true
isServerError(404) // false
isError(404) // true
```---
## ๐License
> [MIT License](./LICENSE)