🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@metatypes/http-statuses

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metatypes/http-statuses

Well-Documented HTTP Status Code Enums

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
26
-86.46%
Maintainers
1
Weekly downloads
 
Created
Source

@metatypes/http-statuses

Complete, well-documented HTTP Status Code definitions for TypeScript Projects.

Usage

import { Statuses } from '@metatypes/http-statuses'

async function fetchUsers() {
	const response = await fetch(/* ... */)

	switch (response.status) {
		case Statuses.HTTP_200_OK:
			return response.data

		case Statuses.HTTP_404_NOT_FOUND:
			alert('the user could not be found')
			break

		default:
			throw new Error('Unknown API Error')
	}
}

Framework-Flavored Statuses

For full-stack teams, it might be advantageous to use the same naming scheme on the front- and backend. So, you can also use framework-flavored status codes.

If you’d like to add another framework, feel free to submit a pull request or create an issue.

Django Rest Framework

This is pretty much the same as the default Statuses enum, but status codes that aren’t supported by DRF are removed.

import { DRFStatuses } from '@metatypes/http-statuses'

async function fetchUsers() {
	const response = await fetch(/* ... */)

	switch (response.status) {
		case DRFStatuses.HTTP_200_OK:
			return response.data

		case DRFStatuses.HTTP_404_NOT_FOUND:
			alert('the user could not be found')
			break

		default:
			throw new Error('Unknown API Error')
	}
}

Node.js

import { NodeJsStatuses } from '@metatypes/http-statuses'

async function fetchUsers() {
	const response = await fetch(/* ... */)

	switch (response.status) {
		case NodeJsStatuses.OK:
			return response.data

		case NodeJsStatuses.NotFound:
			alert('the user could not be found')
			break

		default:
			throw new Error('Unknown API Error')
	}
}

Spring Framework

import { SpringStatuses } from '@metatypes/http-statuses'

async function fetchUsers() {
	const response = await fetch(/* ... */)

	switch (response.status) {
		case SpringStatuses.OK:
			return response.data

		case SpringStatuses.NotFound:
			alert('the user could not be found')
			break

		default:
			throw new Error('Unknown API Error')
	}
}

Keywords

code

FAQs

Package last updated on 07 Aug 2020

Did you know?

Socket

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