Setu-TS
    Preparing search index...

    Interface IResponse

    Runtime-agnostic response builder. Configuration methods (status, header) chain; terminal methods (json, text, send, redirect) produce the HandlerResult a route handler returns.

    app.router.get('/users/:id', (ctx) => {
    return ctx.response.status(200).json({ id: ctx.params.id });
    });

    0.1.0

    interface IResponse {
        appendHeader(name: string, value: string): IResponse;
        header(name: string, value: string): IResponse;
        html(body: string): HandlerResult;
        json<T>(body: T): HandlerResult;
        redirect(url: string, status?: number): HandlerResult;
        send(body?: Uint8Array<ArrayBufferLike>): HandlerResult;
        setHeaders(headers: Readonly<Record<string, string>>): IResponse;
        snapshot(): ResponseSnapshot;
        status(code: number): IResponse;
        stream(body: ReadableStream<Uint8Array<ArrayBufferLike>>): HandlerResult;
        text(body: string): HandlerResult;
    }

    Implemented by

    Index
    • Appends a response header, preserving any existing values for the same name rather than replacing them (unlike IResponse.header, which overwrites). This is the correct way to emit multiple headers of the same name — most notably several Set-Cookie headers (e.g. an access cookie plus a refresh cookie, or deleting several cookies at once).

      Parameters

      • name: string

        Header name

      • value: string

        Header value to add

      Returns IResponse

      This response, for chaining

    • Sends an HTML response.

      The text/html; charset=utf-8 media type is set explicitly — a bare text/html lets a browser sniff the encoding.

      Parameters

      • body: string

        The HTML document text

      Returns HandlerResult

      The handler result

      0.2.0

    • Sets several response headers at once — the same as calling IResponse.header for each own enumerable string-keyed entry, in order, with the same validation and the same errors.

      For a header set a middleware sends on every response, pass the SAME frozen object each time: the kernel validates it once and then copies it into each response in one step (measured at 941 → 358 ns per response on Bun). Any other object is applied entry by entry. A frozen object is the contract for the shortcut because it cannot change after it was checked.

      Parameters

      • headers: Readonly<Record<string, string>>

        Header names and values

      Returns IResponse

      This response, for chaining

      const SECURITY_HEADERS = Object.freeze({ 'x-content-type-options': 'nosniff' });
      app.middleware.add(async (ctx, next) => {
      ctx.response.setHeaders(SECURITY_HEADERS);
      await next();
      });

      0.11.0

    • Returns a snapshot of the current response state (status, headers, body). Enables middleware to inspect the response after next() returns — required for transparent response caching.

      The returned object is a READ view, not a defensive copy: headers is the live Headers instance backing the response. Treat it as read-only — mutating it mutates the response. (No copy is taken deliberately: cloning a Headers collapses repeated Set-Cookie values into one comma-joined header, which would corrupt multi-cookie responses.)

      Returns a discriminated union keyed on streaming: when false, body is Uint8Array | string | null (buffered); when true, body is a ReadableStream<Uint8Array> (live stream). Middleware that reads the body (e.g. cache middleware) must check streaming first to avoid draining a live stream.

      Returns ResponseSnapshot

      The status code, headers, and either a buffered body or a live stream

      0.1.0

    • Sends a streaming response body.

      Accepts a web-standard ReadableStream so that a handler can flush bytes progressively over a long-lived connection instead of buffering a whole body before send. This is the shared foundation for Server-Sent Events (Milestone 43), React SSR streaming (Milestone 44), large file downloads (storage-plugin, Milestone 28), and export / report responses.

      Because the runtime maps the response to a web-standard new Response(streamBody, { status, headers }), streaming is free on every platform (Node via Hono, Deno, Bun, Cloudflare Workers) with no buffer-then-send.

      Parameters

      • body: ReadableStream<Uint8Array<ArrayBufferLike>>

        A ReadableStream of Uint8Array chunks

      Returns HandlerResult

      The handler result

      0.2.0