variable / @typed/ui

ssrForHttp

Registers buffered, GET-only HTML routes for a matcher.

Path captures take precedence over same-named query parameters. Rendering completes before the response is created; this adapter does not stream.

Learn this UI primitive →

Package version
1.0.0-beta.13
Category
Buffered server rendering
Since
1.0.0

Import

import { ssrForHttp } from "@typed/ui";

Signatures

export declare const ssrForHttp: {
    <E, R>(input: Matcher<RenderEvent, E, R>): (router: HttpRouter) => SsrForHttpEffect<E, R>;
    <E, R>(router: HttpRouter, input: Matcher<RenderEvent, E, R>): SsrForHttpEffect<E, R>;
};

Why

Typed route matchers already describe decoding, guards, parent prefixes, and render output. ssrForHttp installs that same model in Effect’s HttpRouter and buffers one complete HTML document for runtimes that require a known body.

Ownership and lifetime

Registration adds GET routes to the supplied Effect HttpRouter. Each request creates request-local memory navigation and current-route services; the request Effect owns rendering and all finalizers. Buffered rendering must complete before the response is returned. Rendering HTML does not mount or hydrate a browser client.

Routing behavior

Matcher cases sharing a path are tried in their compiled order. Path params overwrite same-named query params. Decode/guard failures continue candidate selection; a matched renderer failure stays in the typed request error channel.

Examples

import { ssrForHttp } from "@typed/ui/HttpRouter"
import { Effect } from "effect"
import * as HttpRouter from "effect/unstable/http/HttpRouter"
import { Parse, match } from "@typed/router"
import { html } from "@typed/template"

const pages = match(Parse("/"), html`<h1>Home</h1>`)
const routes = Effect.gen(function* () {
  const router = yield* HttpRouter.make
  yield* ssrForHttp(router, pages)
  return router
})

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source