> For AI agents: the complete documentation index is available at https://navios.tech/llms.txt, the full documentation bundle is available at https://navios.tech/llms-full.txt.

# Navios Builder

`@navios/builder` turns a description of an HTTP endpoint — method, URL, schemas — into a typed function that validates what it sends and what it receives. You write the description once and use it from the browser, from a Navios server controller and from React Query hooks.

```ts
import { builder } from '@navios/builder'
import { create } from '@navios/http'
import { z } from 'zod/v4'

const API = builder({ client: create({ baseURL: 'https://api.example.com' }) })

export const getUser = API.declareEndpoint({
  method: 'GET',
  url: '/users/$userId',
  responseSchema: z.object({ id: z.string(), name: z.string() }),
})

const user = await getUser({ urlParams: { userId: '42' } })
//    ^? { id: string; name: string }
```

## One declaration, three places

The value `getUser` is the contract. Everything else is derived from it.

**Call it** from any TypeScript code:

```ts
const user = await getUser({ urlParams: { userId: '42' } })
```

**Implement it** in a Navios server controller. The handler's parameters and return type come from the same declaration:

```ts
import { Controller, Endpoint } from '@navios/server'

import type { HandlerParams } from '@navios/server'

@Controller()
class UserController {
  @Endpoint(getUser)
  async getUser({ urlParams }: HandlerParams<typeof getUser>) {
    return { id: urlParams.userId, name: 'Ada' }
  }
}
```

**Use it** as a React Query hook:

```tsx
import { declareClient } from '@navios/react-query'

const client = declareClient({ api: API })
const userQuery = client.query(getUser)

function UserName({ userId }: { userId: string }) {
  const { data } = userQuery.use({ urlParams: { userId } })
  return <span>{data?.name}</span>
}
```

Change the response schema and all three stop compiling until they agree again.

## What you get

- **Inferred types.** Arguments, results and error bodies are inferred from the URL template and the schemas. You never write a request or response type by hand.
- **Validation on both sides of the wire.** Input is checked before a request is sent; the response is checked before your code sees it.
- **One error type.** Every failed call is an `EndpointError` with a `kind` you can switch on. Let it throw, or call `.safe()` and receive it as a value.
- **Your schema library.** Every schema slot accepts any [Standard Schema](https://standardschema.dev) implementation: Zod, Valibot, ArkType and others. These docs use Zod in examples.
- **Your HTTP client.** `@navios/http`, axios, or a small `fetch` wrapper.
- **More than JSON.** Multipart uploads, file downloads, text, streams and empty replies come from the same `declareEndpoint`. WebSocket and Server-Sent Events have their own typed builders.

## Where to go

| You want to…                            | Read                                                                                                      |
| --------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| get an endpoint working                 | [Quick start](https://navios.tech/docs/builder/quick-start.md)                                            |
| understand the model first              | [How it works](https://navios.tech/docs/builder/how-it-works.md)                                          |
| learn the everyday API in order         | Essentials, starting with [Declaring endpoints](https://navios.tech/docs/builder/essentials/endpoints.md) |
| find out why a call failed              | [Errors](https://navios.tech/docs/builder/essentials/errors.md)                                           |
| share declarations with a Navios server | [Sharing with Navios Server](https://navios.tech/docs/builder/guides/navios-server.md)                    |
| use endpoints in React components       | [React Query](https://navios.tech/docs/builder/react-query/index.md)                                      |
| look up an option, type or export       | [API reference](https://navios.tech/docs/builder/reference/builder.md)                                    |
| upgrade from 1.x                        | [Migrating to 2.0](https://navios.tech/docs/builder/reference/migrating-to-2.md)                          |
