@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:
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