0.5.2 • Published 5 months ago

http-codex v0.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

http-codex

A simple library for http status codes, adapted from Go's http package.

Usage

Install

# Install using your favorite package manager:
npm install http-codex
pnpm add http-codex
bun add http-codex
yarn add http-codex

Example

import { httpStatus } from 'http-codex'

const res = new Response('hello world!', {
	status: httpStatus.OK, // 200
	statusText: httpStatus.text(httpStatus.OK), // 'OK'
})

If preferred, status codes can be imported by themselves to reduce bundle size:

import { httpStatus } from 'http-codex/status'

const status = httpStatus.OK // 200

Additional Helpers

isNullBodyStatus

Helper function that returns whether the status should have a null body:

import { httpStatus, isNullBodyStatus } from 'http-codex'

const res = await fetch(url) // Might be 204, 304, etc.
return new Response(isNullBodyStatus(res.status) ? null : res.body, {
	// Useful for when we need to customize response headers/init/etc.
})

Bundle Size

Here are the bundle sizes of each import:

ImportMinifiedMinified + Gzip'd
http-codex4.1 KB1.46 KB
http-codex/status1.2 KB728 bytes

Note: http-codex/status is smaller because it excludes the statusText() function.

Why Another HTTP Status Code Library?

Honestly I just love Go and wanted one that was very similar to how Go's http package works.

0.4.5

6 months ago

0.4.6

6 months ago

0.5.0

5 months ago

0.5.2

5 months ago

0.5.1

5 months ago

0.4.4

9 months ago

0.4.3

9 months ago

0.4.2

9 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.3.2

9 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.2

9 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago