Beignet API reference
    Preparing search index...

    Interface ServerInstance<Ctx, Ports, ServiceInput>

    Runtime server object returned by createServer(...).

    interface ServerInstance<
        Ctx,
        Ports extends AnyPorts = AnyPorts,
        ServiceInput = void,
    > {
        api: (req: HttpRequestLike) => Promise<HttpResponse>;
        contracts: readonly HttpContractConfig[];
        createRequestContext: (req: HttpRequestLike) => Promise<Ctx>;
        createServiceContext: (
            ...args: ServiceContextInputArgs<ServiceInput>,
        ) => Promise<Ctx>;
        ports: Ports;
        rawRoute: (init: RawRouteInit) => RawRouteBuilder<Ctx>;
        route: <CLike extends ContractLike>(
            contractLike: CLike,
        ) => RouteBuilder<Ctx, ResolveContract<CLike>>;
        runServiceContext: <T>(
            ...args: [
                ...ServiceContextInputArgs<ServiceInput>[],
                fn: (ctx: Ctx) => T | Promise<T>,
            ],
        ) => Promise<T>;
        stop: () => Promise<void>;
    }

    Type Parameters

    Index
    api: (req: HttpRequestLike) => Promise<HttpResponse>

    Catch-all request handler for platform adapters.

    contracts: readonly HttpContractConfig[]

    Contract configs registered through the routes option.

    createRequestContext: (req: HttpRequestLike) => Promise<Ctx>

    Build a fully assembled request context from a framework-neutral request.

    Use this for adapter entry points outside the route pipeline, such as server components or upload routes.

    createServiceContext: (
        ...args: ServiceContextInputArgs<ServiceInput>,
    ) => Promise<Ctx>

    Build a fully assembled service context for schedules, outbox drains, tasks, and background work.

    Requires context.service to be declared in createServer(...).

    Only call this from long-lived runtimes such as servers, workers, and bun test. It enters the ambient correlation context with AsyncLocalStorage.enterWith, and resuming that frame across top-level await crashes Bun 1.3.x in plain scripts. Seeds and one-off scripts must use runServiceContext(...) instead.

    ports: Ports

    Final app ports after provider setup.

    rawRoute: (init: RawRouteInit) => RawRouteBuilder<Ctx>

    Build a handler for a route that cannot be a contract — webhooks, third-party auth callbacks, streaming endpoints — that still runs the whole server pipeline: correlation, onRequest, route hooks, beforeHandle, beforeSend, afterSend, context creation, instrumentation, and framework error mapping.

    Request parsing and validation are skipped and the request body is left unconsumed, so the handler owns body reading — for example webhook signature verification over the exact raw bytes. Metadata-driven hooks such as rate limiting and idempotency read init.metadata. Raw routes are not added to the route registry; mount the returned handler at the route's own path.

    route: <CLike extends ContractLike>(
        contractLike: CLike,
    ) => RouteBuilder<Ctx, ResolveContract<CLike>>

    Register and build a single route handler imperatively.

    runServiceContext: <T>(
        ...args: [
            ...ServiceContextInputArgs<ServiceInput>[],
            fn: (ctx: Ctx) => T | Promise<T>,
        ],
    ) => Promise<T>

    Build a service context and run fn inside a scoped ambient correlation frame, returning its result.

    This is the script-safe counterpart to createServiceContext(...): the ambient frame is entered with AsyncLocalStorage.run, so plain scripts such as seeds and one-off maintenance work stay safe under top-level await. Requires context.service to be declared in createServer(...).

    stop: () => Promise<void>

    Stop installed providers in reverse setup order.