@orveth/http
Shared HTTP constants and tiny response helpers. @orveth/server uses these primitives when serializing JSON and text responses; application code can import the same utilities for consistency outside the built-in runtime.
Exports at a glance
| Symbol | Role |
|---|---|
HttpStatus | Curated numeric status constants reused across packages. |
HttpStatusCode | Union type of literals contained in HttpStatus. |
ContentType | Common Content-Type header values (JSON, plain text, HTML) with UTF-8 charset. |
prepareJsonResponse | Builds status, headers, and JSON-encoded body via JSON.stringify. |
prepareTextResponse | Builds status, headers, and UTF-8 plain text body. |
prepareJsonErrorResponse | Thin wrapper for minimal { code, message } JSON error payloads. |
getHeader, normalizeHeaderName, acceptsJson | Header inspection helpers operating on a RawHeaders map. |
RawHeaders | Read-only record compatible with Node's IncomingHttpHeaders shape without importing Node types. |
HttpStatus constants
The object is intentionally small. It covers the statuses Orveth libraries reference today, not every valid HTTP code.
| Key | Value |
|---|---|
HttpStatus.OK | 200 |
HttpStatus.CREATED | 201 |
HttpStatus.NO_CONTENT | 204 |
HttpStatus.BAD_REQUEST | 400 |
HttpStatus.UNAUTHORIZED | 401 |
HttpStatus.FORBIDDEN | 403 |
HttpStatus.NOT_FOUND | 404 |
HttpStatus.CONFLICT | 409 |
HttpStatus.UNPROCESSABLE_ENTITY | 422 |
HttpStatus.TOO_MANY_REQUESTS | 429 |
HttpStatus.INTERNAL_SERVER_ERROR | 500 |
HttpStatus.NOT_IMPLEMENTED | 501 |
HttpStatus.BAD_GATEWAY | 502 |
HttpStatus.SERVICE_UNAVAILABLE | 503 |
Response preparation
prepareJsonResponse(status, payload) sets content-type to ContentType.jsonUtf8 and returns { status, headers, body }. prepareTextResponse(status, body) mirrors that flow for plain text.
import { HttpStatus, prepareJsonResponse } from "@orveth/http";
export function healthPayload() {
return prepareJsonResponse(HttpStatus.OK, {
status: "ok",
uptimeSeconds: process.uptime(),
});
}Header helpers
getHeader(headers, name) performs case-insensitive lookup. acceptsJson inspects Accept for an application/json media range, which is useful when deciding whether to emit JSON or HTML from higher-level handlers.
import { acceptsJson, type RawHeaders } from "@orveth/http";
export function prefersJson(headers: RawHeaders): boolean {
return acceptsJson(headers);
}Relationship to other packages
@orveth/serverconsumes these helpers when writingctx.jsonandctx.text, and when mapping thrown errors to HTTP responses.@orveth/errorsremains the home for error classes; this package does not define new error types.