Skip to content
Library design

HTTP Status Codes Are Data, Not a Switch Statement

A small, type-safe library of standards-backed HTTP status codes for Node.js and browsers.

Get http-status-lite on npm
2 min read0 comments
Website

Why it was needed

Developers need status-code names, categories, and lifecycle metadata. Without a library they fall back on memorized numeric checks or hand-written lists that go stale, and many alternatives bring a heavier dependency than the task needs.

The IANA registry changes over time. Obsolete, temporary, and unused codes must remain distinguishable. Typing and ESM and CommonJS compatibility must not depend on live network access.

How it is built

A committed snapshot of the IANA registry generates the typed library. Constants, predicates, and metadata are exposed as separately importable entry points, and a workspace-linked interactive reference plus automated registry and release workflows keep the snapshot and package in step.

Commit the registry snapshot. Builds read a reviewed file instead of fetching the registry at runtime, which makes them deterministic. The trade-off is periodic maintenance when the registry changes.

Preserve lifecycle metadata. Flattening every number to "valid" would hide whether a code is permanent, temporary, obsolete, or unused, which is information callers can need.

Expose separate entry points. Focused imports let consumers pull in only what they use, while the main entry point still offers the complete API.

The key decision: Commit the registry snapshot.

What changed

Built the typed registry, lookups, parsers, and status-class predicates. Modeled permanent, temporary, obsolete, and unused entries. Added generator drift checks and package publishing gates. Implemented an interactive status reference that consumes the local library.

Consumers can retrieve name, category, and lifecycle metadata for status codes. Consumers can classify codes into success, client error, and server error categories. Consumers can parse and validate status codes. Builds rely on a reviewable standards snapshot without runtime network access.

My role: Library design and package engineering. Scope: Typed APIs, compatibility, and package distribution.

Working through a similar challenge?

Share your context, constraints, and timeline to start a focused conversation.