@orveth/http
v0.1.1
Published
HTTP status constants, response preparation, and header utilities.
Readme
@orveth/http
Package name
@orveth/http
Purpose
Shared HTTP constants and small, dependency-free helpers for header handling and preparing JSON/text responses.
Installation
pnpm add @orveth/httpBasic usage
import {
HttpStatus,
acceptsJson,
getHeader,
prepareJsonErrorResponse,
prepareJsonResponse,
prepareTextResponse,
} from "@orveth/http";
const headers = { authorization: "Bearer token", accept: "application/json, text/plain" };
const auth = getHeader(headers, "authorization");
const wantsJson = acceptsJson(headers);
const json = prepareJsonResponse(HttpStatus.OK, { ok: true });
const text = prepareTextResponse(HttpStatus.OK, "pong");
const problem = prepareJsonErrorResponse(HttpStatus.BAD_REQUEST, {
code: "ORVETH_EXAMPLE",
message: "Bad request",
});API overview
Exports include:
HttpStatusnumeric constants andHttpStatusCodetypeContentTypecommonContent-Typeheader valuesprepareJsonResponse,prepareTextResponse,prepareJsonErrorResponse- Header helpers:
normalizeHeaderName,getHeader,acceptsJson, andRawHeaders
Design notes
This package intentionally does not include a full HTTP client or server. It is shared infrastructure for libraries like @orveth/server.
Error behavior
prepareJsonResponse uses JSON.stringify and will throw if serialization throws (for example due to circular structures).
TypeScript notes
This package ships .d.ts declarations and is authored in TypeScript strict mode.
License
Released under the MIT License. See the repository LICENSE file.
