This example demonstrates how to use OpenAPI TypeScript with Nuxt 3, leveraging the officialDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/hey-api/openapi-ts/llms.txt
Use this file to discover all available pages before exploring further.
@hey-api/nuxt plugin for seamless integration with Nuxt’s composables.
Configuration
Nuxt Config
Configure the Hey API plugin directly innuxt.config.ts:
nuxt.config.ts
- Configuration embedded in
nuxt.config.ts - Automatic client generation on dev server start
- No separate
openapi-ts.config.tsneeded transformer: true- Enable data transformationvalidator: true- Runtime validation with Zod
Package Dependencies
package.json
Application Setup
App Configuration
Configure the global client inapp.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 foruseAsyncData + $fetch:
useLazyAsyncData
Non-blocking data fetching:useLazyFetch
Shorthand foruseLazyAsyncData + $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
Withtransformer: true, dates are automatically converted:
Runtime Validation
Withvalidator: true, responses are validated: