Socket
Socket
Sign inDemoInstall

@cdellacqua/http-status

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cdellacqua/http-status

HTTP Status TypeScript enums


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Enums for HTTP Status Codes and Messages

NPM Package

npm install @cdellacqua/http-status

Documentation

Highlights

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);
	}
});

Keywords

FAQs

Last updated on 11 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc