Skip to content

Create and serve an HTTP application ​

ChoWeb.create initializes the dependency graph, compiles HTTP routes and passes them to a linker. The returned application is ready to accept a Request. Starting a network listener is a separate operation.

ts
import { ChoWeb } from "@chojs/web";
import { serve } from "@chojs/web/serve";
import { Library } from "./app.ts";

const app = await ChoWeb.create(Library, { prefix: "api" });
const server = await serve(app.handler, { port: 3000 });
console.log("Listening on", server.port);

Options ​

OptionEffect
prefixPrepends relative segments to controller routes
linkerRegisters compiled routes with a router. Defaults to ChoLinker
onErrorSupplies the fallback error handler for matched routes
overridesReplaces matching provider declarations before initialization

If initialization or linking fails, creation rejects and CHO attempts to release instances already created. Start the listener only after creation succeeds.

What the application exposes ​

Use app.handler for serving and request tests. Use app.routes to inspect final method/path pairs and their diagnostic names. app.graph retains feature, controller and method metadata for tools such as API documentation generators. app.linked.instance exposes the selected adapter's native application. app.injector can be shared with a message consumer.

After creation, call app.mount to register endpoints that depend on the initialized application. These join app.routes with their own names and full paths. Register them before a listener, test request or adapter readiness check. Mount a route · Publish OpenAPI documentation

Shut down the listener ​

Await server.close() to stop accepting requests and drain active connections. Then await app.close() to dispose providers. Subsequent requests passed to app.handler receive 503. Use closeTimeout when a long-lived stream could keep a listener open. Graceful shutdown

Released under the MIT License.