Skip to main content
defineEndpoint is for teams without an OpenAPI spec. If you have one, run kweri-gen instead — it generates all endpoint definitions automatically and you can skip this page entirely.

What is an endpoint?

An endpoint is a plain object that describes an API route — its HTTP method, path, parameter schema, and response schema:
Kweri uses the schemas at runtime to validate request params before any network call fires, and at the TypeScript level to infer the types of params and response.

defineEndpoint

defineEndpoint is an identity function that provides type inference:
You can also define the endpoint inline anywhere — defineEndpoint is entirely optional. It only exists to surface TypeScript errors closer to the definition site.

Path parameters

Use {name} placeholders in the path. The matching path object in params provides the values:

Query parameters

Keys in a query object are appended as query string parameters:

Request body

Use a body key for POST/PUT/PATCH payloads:

Combined path, query, and body

Type inference

Use InferParams and InferResponse to extract the TypeScript types from an endpoint:

TypeBox schema reference

Kweri re-exports Type and Static from @sinclair/typebox:

Runtime validation

Params are not validated at runtime. When kweri.query() and kweri.mutate() call the API client internally, they replace the endpoint’s params schema with Type.Any() before executing the request. This means the TypeBox params schema is purely a TypeScript-level construct — it drives type inference for InferParams<E> but is never evaluated against your actual values at runtime. Responses are validated at runtime. After a successful fetch, kweri checks the server’s response against the endpoint’s response schema. If the shape doesn’t match, a ValidationError is thrown:
For params, TypeScript is your enforcement layer — passing the wrong type is a compile error, not a runtime error.