Documentation

Responses

Choose between success bodies, status-aware typed results, and raw Web Responses.

The generated client exposes each route call with a few response shapes. Pick the one that matches the calling code instead of hand-writing $fetch calls.

Success body

Awaiting the call directly returns the declared success body. This is the smallest shape for UI code that only cares about a successful result.

All JSON response helpers expose wire types. For example, a server response schema whose output contains Date is validated as Date in the handler and received as string by the client. The same conversion applies to status-specific error bodies.

const user = await $endpoint('/api/users/:id', {
  method: 'get',
  params: { id: '123' },
})

user.id.toFixed()
user.name.toUpperCase()

Typed result

Use .result() when the endpoint declares multiple statuses and the caller needs to branch on the status code. The result includes status, ok, body, and headers.

const result = await $endpoint('/api/users/:id', {
  method: 'get',
  params: { id: '404' },
}).result()

if (result.status === 404) {
  result.body.message
}
if (result.status === 200) {
  result.body.name
}

This helper is generated by default. Set endpoints.client.result to false if the project only wants the default body call.

For Nuxt async data, use useEndpointResult. It keeps status, ok, and body typed, but does not include non-serializable Headers.

const { data: result } = await useEndpointResult('/api/users/:id', {
  method: 'get',
  params: { id: '123' },
})

if (result.value?.status === 404) {
  result.value.body.message
}

Raw Web Response

Use .raw() when code needs a native Response shape, such as streaming, headers-first logic, or passing the result into lower-level utilities. For contracted JSON responses, the json() return type follows the serialized wire representation of the endpoint response schema.

const response = await $endpoint('/api/users/:id', {
  method: 'get',
  params: { id: '123' },
}).raw()

if (response.status === 200) {
  const body = await response.json()
  body.id
}

This helper is generated by default. Set endpoints.client.raw to false to remove it from the client surface.

There is no useEndpointRaw. Raw Web Responses are intentionally kept on $endpoint(...).raw() because native Response and Headers values do not fit Nuxt async-data payloads cleanly.