Documentation

Mental Model

One route definition powers the server, client, and documentation.

Nuxt Endpoints adds a typed contract around ordinary Nuxt server routes. That contract is the source for runtime validation, generated client calls, and OpenAPI output. Six principles explain how every feature fits together.

1. Route files stay Nuxt-native

You still write ordinary files under server/api and export an event handler. The endpoint definition wraps the HTTP boundary.

2. Schemas describe HTTP input and output

Zod, Valibot, and Effect Schema definitions describe the data that crosses the HTTP boundary. Handler context types use parsed schema output, so coercion and transforms are reflected in application code.

3. Route paths become client calls

On Nuxt 4.6, call a concrete URL such as /api/users/1 with $fetch or useFetch. Enable native fetch types for status-aware JSON responses.

Each endpoint route is also generated onto $endpoint('/path', { method }) calls with typed request options. A route may also declare a unique name for a shorter $endpoint.getUser({ params }) alias. The alias keeps the same explicit HTTP input slots and returns the same lazy request, which can be awaited, passed to Pinia Colada, or read as a raw Web Response. Path and method remain the canonical HTTP identity.

4. Response handling is explicit

With useFetch, data.value holds the successful body. Check error.value?.status to narrow its error data. With $fetch.raw and ignoreResponseError: true, check response.status to narrow response._data.

With $endpoint, await the request to receive a typed status union. Use .raw() only when code needs a low-level Web Response. useEndpoint and the Pinia Colada options keep the same status-aware data shape while omitting native headers.

5. OpenAPI is generated from the same source

The module can serve an OpenAPI 3.1 document without maintaining a separate route registry.

6. Server-state adapters remain optional

On Nuxt 4.6 with native fetch types enabled, pass an endpoint URL to queryOptions, mutationOptions, or infiniteQueryOptions. These adapters also accept $endpoint request objects. Colada owns cache behavior while Nuxt Endpoints keeps request identity, HTTP idempotency, and response types aligned with the server contract.