Skip to content

The client runtime ​

configure and request — the fetch layer behind every call.

package @smitejs/client

Every generated call funnels through request(method, path, input) in @smitejs/client/runtime. The runtime is a small fetch layer: it interpolates path params, serializes query and body, performs the request, and parses the response. Just HTTP — no server package, no framework, no magic.

Configuring defaults ​

configure({ baseUrl, fetch }) sets module-level defaults. baseUrl is prepended to every path; fetch lets you swap the transport (tests, edge runtimes). Per-call $config overrides these defaults.

ts
configure({
  baseUrl: "https://api.example.com",
  fetch: async () =>
    new Response(JSON.stringify({ ok: true }), { status: 200 }),
});
const response = await request("GET", "/health");
ts
200
{ ok: true }

Making a request ​

request(method, path, input?) is the primitive the generated builders call. Path params are filled into the template, query values become a query string (arrays become repeated params), and object bodies are JSON-serialized with content-type: application/json.

ts
configure({
  baseUrl: "https://api.example.com",
  fetch: async () =>
    new Response(JSON.stringify({ id: "42" }), { status: 200 }),
});
const response = await request("GET", "/users/:id", {
  params: { id: "42" },
  query: { verbose: "1" },
});
ts
200
{ id: "42" }

Response handling ​

The body is parsed as JSON when possible, falling back to raw text. The response is normalized to { status, body, headers }, and non-2xx statuses are returned rather than thrown — mirroring the server's serve contract.

Released under the MIT License.

/ search•[ ] prev/next•j/k scroll•h home•t theme•guide/techniques/client-runtime