Skip to main content
This example demonstrates how to use OpenAPI TypeScript with Nuxt 3, leveraging the official @hey-api/nuxt plugin for seamless integration with Nuxt’s composables.

Configuration

Nuxt Config

Configure the Hey API plugin directly in nuxt.config.ts:
nuxt.config.ts
Key features:
  • Configuration embedded in nuxt.config.ts
  • Automatic client generation on dev server start
  • No separate openapi-ts.config.ts needed
  • transformer: true - Enable data transformation
  • validator: true - Runtime validation with Zod

Package Dependencies

package.json

Application Setup

App Configuration

Configure the global client in app.vue:
app.vue

Usage

Component with Multiple Composables

Nuxt provides multiple composables for different use cases:
components/home.vue

Nuxt Composables

The @hey-api/nuxt plugin generates SDK methods that work with all Nuxt data fetching composables:

useAsyncData

Fetch data during SSR and hydrate on client:

useFetch

Shorthand for useAsyncData + $fetch:

useLazyAsyncData

Non-blocking data fetching:

useLazyFetch

Shorthand for useLazyAsyncData + $fetch:

$fetch

Direct fetch without SSR hydration:

Advanced Features

Request Forwarding

Forward user headers to server routes:

Reactive Queries

Watch reactive values and refetch automatically:

Data Transformation

With transformer: true, dates are automatically converted:

Runtime Validation

With validator: true, responses are validated:

Key Features

Type Safety

Full TypeScript support with Nuxt composables:

SSR Support

Seamless server-side rendering:

Auto Imports

SDK methods are auto-imported:

Running the Example

1

Clone the repository

2

Install dependencies

3

Run the Nuxt example

4

Open in browser

Navigate to http://localhost:3000

Full Example

View the complete example in the repository: Nuxt Example on GitHub

Learn More

Nuxt Plugin

SDK Plugin

Transformers Plugin

Examples Overview