Clients
The clients plugin generates resource-based client classes and request commands from your Typeweaver spec. Instead of hand-writing URLs, payload types, and response parsing, you call your API through generated, contract-aware client code.
Install note
For client generation, add the plugin package:
npm install -D @rexeus/typeweaver-clients
What gets generated
For a todo resource with a getTodo operation, Typeweaver generates artifacts such as:
TodoClientGetTodoRequestCommand- request and response types
- request and response validators
Calling an operation
import { GetTodoRequestCommand, TodoClient } from "./api/generated";
const client = new TodoClient({
baseUrl: "/api",
});
const response = await client.send(
new GetTodoRequestCommand({
param: {
todoId: "todo_123",
},
}),
);
if (response.type === "GetTodoSuccess") {
console.log(response.body.title);
}
baseUrl is required. fetchFn and timeoutMs are optional.
If your runtime already provides a global fetch, baseUrl is enough. Pass fetchFn only when you need a custom transport, such as in tests, on older Node.js setups, or inside a wrapper that decorates fetch.
The important part is the flow:
- Create the generated client for the resource.
- Create the generated request command for the operation.
- Send the command.
- Branch on
response.typeto handle the allowed outcomes.
Why this helps
Generated clients reduce contract drift because the caller uses artifacts built from the same spec as the server-side validators and handlers.
That means:
- request shapes stay aligned with the spec
- response handling stays aligned with the declared responses
- renaming an operation or changing a schema shows up in generated code immediately
This page is about the generated surface
This page is about what the clients plugin generates. For constructor options and day-to-day calling patterns, see Basic Usage.
Most teams mainly work with:
- the resource client, such as
TodoClient - the request command for a specific operation
- the response union returned by
send(...)