https://github.com/cdellacqua/http-status.js
Enums for HTTP Status Codes and Messages
https://github.com/cdellacqua/http-status.js
http
Last synced: about 1 year ago
JSON representation
Enums for HTTP Status Codes and Messages
- Host: GitHub
- URL: https://github.com/cdellacqua/http-status.js
- Owner: cdellacqua
- License: mit
- Created: 2021-11-26T10:58:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T16:25:32.000Z (about 2 years ago)
- Last Synced: 2025-03-14T23:12:06.623Z (about 1 year ago)
- Topics: http
- Language: TypeScript
- Homepage:
- Size: 119 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Enums for HTTP Status Codes and Messages
[NPM Package](https://www.npmjs.com/package/@cdellacqua/http-status)
`npm install @cdellacqua/http-status`
[Documentation](https://github.com/cdellacqua/http-status.js/blob/main/docs/README.md)
## Highlights
```js
import {HttpStatus, HttpStatusMessage} from '@cdellacqua/http-status';
console.log(HttpStatus.OK); // 200
console.log(HttpStatusMessage[301]); // "Moved Permanently"
console.log(HttpStatusMessage[HttpStatus.MovedPermanently]); // "Moved Permanently"
// It can be used to create expressive dispatch tables:
const dispatchTable = {
[HttpStatus.OK]: async (response) => alert('here we go: ' + (await response.text())),
[HttpStatus.InternalServerError]: () => alert('oops!'),
[HttpStatus.BadRequest]: () => alert('mistakes were made...'),
};
fetch('/some-api.json').then((response) => {
if (response.status in dispatchTable) {
dispatchTable[response.status](response);
} else {
alert('unhandled status! ' + response.status);
}
});
```