---
url: /fetch/intro.md
description: >-
  KosmoJS automatically derives fully-typed fetch clients with runtime
  validation for every API route. End-to-end type safety from frontend to
  backend with validation schemas and URL utilities.
---

When you define an API route with typed parameters, payloads, and responses,
KosmoJS derives a corresponding fetch client - automatically, as part of the same build step.

The result is a fully-typed client that mirrors your route definition exactly.
Parameters, payload shape, response type - all derived from the same source.
Change your API, and the client updates with it. No manual sync required.

The client is derived into `var/lib/<folder>/fetch/` and reached as `_/fetch`.
You import it; you never edit it - `var/lib/` is [regenerated](/essentials/project-structure.md#path-mappings) on every change.

## What Gets Derived

Each route's client module exports:

🔹 **HTTP method functions** - `GET`, `POST`, `PUT`, etc., accepting parameters and payloads
typed to match your route definition and returning typed response promises.
[Details ›](/fetch/start.md)

🔹 **`path` and `href` utilities** - construct relative or absolute URLs with proper
parameter substitution and optional query string support.
[Details ›](/fetch/utilities.md)

🔹 **`validationSchemas`** - the same schemas used for server-side validation,
exposed for client-side form validation with `check`, `errors`, `errorMessage`,
`errorSummary`, and `validate` methods.
[Details ›](/fetch/validation.md)

## Using the Client

Import the fetch map and pick the client for your route by path:

```ts [pages/example/index.tsx]
import fetchClients from "_/fetch";

const response = await fetchClients["users/[id]"].GET([123]);
```

Clients land in the `var/lib/` directory alongside other derived artifacts
(validation routines, OpenAPI spec). Everything is updated automatically in the background
as you modify routes during development.

## Isomorphic Clients

The same client works in both CSR and SSR - identical code, no server functions or RPC layer to define.
In the browser it issues a normal same-origin request; during SSR it dispatches to the matched API route in-process,
with no network layer and no round-trip latency.

[Isomorphic clients ›](/fetch/isomorphic-clients.md)
