Configuration
OpenAPI TypeScript Config
Createopenapi-ts.config.ts in your project root:
openapi-ts.config.ts
@hey-api/client-next- Next.js-specific client with App Router supportruntimeConfigPath- Path to client configuration file
Client Configuration
Create a configuration file for the client:src/hey-api.ts
Package Dependencies
package.json
Usage
Client Component
Use'use client' directive for interactive components:
app/page.tsx
Server Component
Server components can directly await API calls:app/pet/[id]/page.tsx
Layout with Interceptors
Configure global interceptors in the root layout:app/layout.tsx
Next.js Features
Caching and Revalidation
Use Next.js caching options with API calls:Dynamic Routes
Type-safe dynamic route parameters:Error Handling
Handle errors gracefully:Metadata Generation
Generate metadata from API responses:Key Features
Type Safety
Full TypeScript support in both server and client components:Server Components
Direct async/await in server components:Request Interceptors
Add authentication and logging:Running the Example
1
Clone the repository
2
Install dependencies
3
Run the Next.js example
4
Open in browser
Navigate to
http://localhost:3000