Skip to content

HTTP API reference ​

Import application classes, decorators and argument readers from @chojs/web. Separate entry points cover listener startup (@chojs/web/serve), the router contract (@chojs/web/linker) and graph nodes (@chojs/web/graph). Generated signatures on JSR

Application and listener ​

APIResult or effect
await ChoWeb.create(Root, options?)Initializes the injector and returns a linked application. Options are prefix, linker, onError and overrides
app.handler(request)Promise of a Fetch Response
app.mount(method, route, handler, options?)Registers a full path on the linked router. Accepts ChoWebMountMethod and ChoWebMountOptions (name, middlewares). Returns void
app.routesDeclared and mounted routes with method, path, name and handle
app.graphFeature, controller and method nodes, including declared inputs and documentation
app.linked.instanceNative router. Defaults to ChoRouter
app.injectorInjector that owns the initialized graph
await app.close()Disposes dependencies and causes subsequent app.handler calls to return 503
await serve(app.handler, options?)Starts a listener on Deno, Bun or Node and returns { runtime, hostname, port, close }

serve accepts port (default 3000, 0 for an allocated port), hostname, signal and closeTimeout in milliseconds. Await server.close() before app.close(). Application lifecycle

Declarations ​

APIDeclares
@Module({ imports, providers, controllers, exports, dependencies, route })Module scope, dependencies and optional feature path
@Controller({ dependencies, route })Constructor inputs and optional controller path
@Injectable(dependencies?), token<T>(description), provider({ provide, deps?, factory })Class and factory providers and typed lookup keys
@Get, @Post, @Put, @Patch, @Delete, @Head, @OptionsOne HTTP method per handler. Each takes a relative route string
@Sse(route, { method?, keepAlive? }?)An async event stream. Defaults to GET
@Args(...readers)Ordered method inputs, followed by the optional ChoWebContext
@Middlewares(...items), @Catch(handler)Route middleware and the nearest route error handler
@Doc(options)Operation IDs, summaries, response statuses and media types, descriptions, tags, security, deprecation and visibility. Field reference

Input and output types ​

SurfaceTypes or helpers
RequestChoWebContext exposes req, url, params, state and native
InputParam, Query, Header, Body, Form and custom ChoWebArg<T> functions
ValidationChoWebValidator<T> supplies parse. validate({ onInvalid? }) activates validators
MiddlewareChoWebMiddlewareFn, ChoWebNext, ChoWebMiddleware
ErrorsChoWebErrorHandlerFn, ChoWebErrorHandler
EventsChoWebSseEvent<T>, ChoWebSseOptions, ChoWebSseResult
MetadataChoWebDoc, ChoWebDocResponse, ChoWebDocSecurity, ChoWebArgInfo

A normal method may return a value or a promise. An SSE method returns an async iterable or an explicit Response. A middleware returns a Response or continues downstream. Responses · Middleware · Events

Router contract ​

Linker<T>.link(routes) returns a Linked<T> with instance, handler and mount(route). ChoLinker accepts { notFound?, middlewares? }. Its ChoRouter exposes routes, mount(route), match(method, pathname) and fetch(request). Adapter comparison · Implement a linker

OpenAPI extra ​

Import openApi(app, options) from @chojs/openapi to serve the specification and optional UI. Use openApiDocument(app, options) for a plain document or docsPage(options) for standalone HTML. Publish an OpenAPI document

Released under the MIT License.