Skip to content

@glandjs/http@1.1.0-beta

API reference

Every public export, grouped by package.

Terminal window
# pnpm pnpm add @glandjs/http @glandjs/express @glandjs/fastify @glandjs/koa @glandjs/hono @glandjs/node
# npm npm install @glandjs/http @glandjs/express @glandjs/fastify @glandjs/koa @glandjs/hono @glandjs/node
# yarn yarn add @glandjs/http @glandjs/express @glandjs/fastify @glandjs/koa @glandjs/hono @glandjs/node
# bun bun add @glandjs/http @glandjs/express @glandjs/fastify @glandjs/koa @glandjs/hono @glandjs/node
Package @glandjs/http
Version 1.1.0-beta
Repository glandjs/http
License MIT
Node >= 20
Dependencies @glandjs/core ^1.0.3-beta · @glandjs/events ^1.1.0 · @medishn/toolkit ^1.0.4 · tslib ^2.8.1
Peer dependencies @glandjs/common ^1.0.3-beta · reflect-metadata ^0.2.2

Every public export, grouped by package. The guides explain when to use each of these; this page is for looking one up.

The framework-agnostic core. No server, no router, no framework import.

Export Kind What it is
HttpCore class The application. Every adapter extends it
HttpBroker class What app.connectTo() takes
HttpApplicationSettings type The shape of app.settings
Member Notes
get post put patch delete head options route verbs, fluent
all trace connect purge search the rest, fluent
propfind proppatch mkcol copy move lock unlock acl report WebDAV, fluent
registerRoute(method, path, action, origin?) for anything else
use(mw) / use(path, mw) Gland middleware
useRaw(...args) framework-native middleware
setErrorHandler(fn) the terminal error renderer
listen(port, options?) bind, and return this
ready() resolves once the socket is bound
close() drain and release
enableCors(config?) the shared CORS middleware
json urlencoded text multipart raw bodyParser parsers
useStaticAssets(root, options?) a static mount
setGlobalPrefix(prefix) idempotent
setViewEngine(engine) / setBaseViewsDir(dir) views, in module form
on(event, fn) / off(event, fn) the lifecycle bus
handleError(error, message) report a transport failure
get adapter instance broker id port the framework, and the bus
get routes middleware settings the route table, the queue, the config

app.on(...) accepts the HttpEvent names.

Constant Fires
HttpEvent.Options construction options
HttpEvent.RouteRegistered a route reached the adapter
HttpEvent.RouteMiss nothing matched
HttpEvent.RequestStart a request was accepted
HttpEvent.RequestEnd a request finished, always
HttpEvent.RequestError a request threw, with the context
HttpEvent.ServerListening the socket is bound
HttpEvent.ServerClosed the socket is released
HttpEvent.ServerCrashed a listener threw, or the server failed to start
Export Kind
HttpContext abstract class — the whole request surface
AcceptType type
Export Kind What it is
HttpReply class An explicit reply. Nine static constructors
ReplyBody ReplyKind ReplyPayload types What a handler may return
HttpReplyOptions type Status, headers, content type, filename
NextFunction type (error?) => Promise<void>
MiddlewareFunction type (ctx, next) => unknown
ErrorHandlerFunction type (error, ctx) => unknown
RouteAction type (ctx, ...args) => unknown
RegisteredRoute type One entry of the route table
Export Kind What it is
HttpServerAdapter abstract class What an adapter implements
MiddlewareEntry type One queued middleware
HttpEventBroker class The lifecycle bus
HttpServerAdapterClass type For a factory function
Export Kind
RequestMethod enum — the wire methods, plus ALL
HTTP_VERBS CORE_HTTP_VERBS ROUTABLE_METHODS ROUTABLE_VERBS ALL_VERB consts
HttpVerb CoreHttpVerb types
toVerb isHttpVerb isCoreVerb isRequestMethod functions

Get Post Put Patch Delete Head Options All Trace Connect Purge Search Propfind Proppatch Mkcol Copy Move Lock Unlock Acl Report RequestMapping.

All from @glandjs/http, not from the adapter — a controller should not change when the transport does.

Export Kind What it is
createCorsMiddleware(config?) function The CORS middleware
errorHandler function The default problem-details renderer
withErrors(handler, onError?) function Return and throw symmetrically
bodyLimit(limit) function Reject an oversized body, before the parsers
toHttpException(error) function Normalise anything into an HttpException
notFoundReply(method, path) const A ready-made 404
Export What it does
normalizePath(path) One leading slash, no trailing slash, no doubles
joinPath(base, child) / is “nothing to add” on either side
applyPrefix(path, prefix) Idempotent prefixing
paramNames(pattern) The parameters in a pattern
splitUrl(url) Path and query
toNamedWildcard(path, name) A bare * for routers that require a name
toReplyPayload(value) The one return-value decision
contentTypeFor(payload) The header for a payload
looksLikeHtml(text) A deliberately narrow sniff
isReadableStream isBinary isSseStream Type guards
baseContentType isJsonContentType isTextContentType isHtmlContentType isEventStreamContentType Content-type helpers
ContentType The values the adapters write
parseCookieHeader(header) Cookie → a bag
serializeCookie(name, value, options) Set-Cookie
SseStream SseEvent SseStreamOptions A live event stream, and a Readable
collectBody(limit) The node:http body collector
Export What it is
HttpEvent The lifecycle event names
GLAND_ROUTE_EVENT The route broadcast, duplicated so the layer is not pinned to one core version
GlandRoute Its payload — { path, fullPath, method, action }
GlandContextState What the binder attaches to ctx.state
isGlandRoute A type guard

HttpApplicationOptions BodyParserOptions JsonBodyParserOptions UrlencodedBodyParserOptions MultipartBodyParserOptions TextBodyParserOptions RawBodyParserOptions CookieOptions SendOptions ErrorCallback RequestCookie RequestCookies HttpsOptions HttpServerOptions CorsOptions CorsConfig CorsOptionsDelegate CorsOptionsCallback StaticOrigin CustomOrigin ServerListening ServerListeningEvent ServerClosedEvent ServerCrashedEvent RequestLifecycleEvent HttpHeaderName HttpHeaderValue HttpHeaderInput HeaderBag ContentTypeValue HttpEventRecord HttpEventKey HttpEventName

Export Kind
ExpressBroker / ExpressBrokerClass What connectTo() takes
ExpressCore The application
ExpressAdapter The adapter
ExpressContext The context
EXPRESS_VERBS ExpressApp Extras
Export Kind
FastifyBroker / FastifyBrokerClass What connectTo() takes
FastifyCore The application, with a typed fastify getter
FastifyAdapter The adapter
FastifyContext FastifyRouteOptions The context
Export Kind
KoaBroker / KoaBrokerClass What connectTo() takes
KoaCore The application, with a typed koa getter
KoaAdapter The adapter
KoaContext KoaState GlandKoaContext The context
Export Kind
HonoBroker / HonoBrokerClass What connectTo() takes
HonoCore The application, with a typed hono getter
HonoAdapter The adapter
HonoRequestContext FetchBodyInit parseFetchBody The context
Export Kind
NodeBroker / NodeBrokerClass What connectTo() takes
NodeCore The application
NodeAdapter The adapter
NodeContext parseBody The context
compile matchSegments The router, exported for tests

The one that catches people:

import { Controller, Channel, Module, On } from '@glandjs/common'; // composition
import { Get, Post, Put, Delete } from '@glandjs/http'; // ROUTES
import { ExpressBroker } from '@glandjs/express'; // transport

Route decorators come from @glandjs/http. A route declared against the adapter package would not survive a transport change, which is the one thing the adapter architecture exists to allow.