Installation
Basic Usage
Configuration
The Next.js client extends the Fetch client with Next.js-specific features:Client Options
HTTP Methods
- GET
- POST
- PUT
- DELETE
Server Components
Use the client in React Server Components:Server Actions
Use the client in Server Actions:Route Handlers
Use in Next.js API routes:Authentication
Server-Side Authentication
Client-Side Authentication
Caching Strategies
Leverage Next.js caching with the fetch options:Force Cache (Default)
No Store (Dynamic)
Revalidate
On-Demand Revalidation
Interceptors
Request Interceptor
Response Interceptor
Error Interceptor
Server-Sent Events
Stream real-time data in client components:Advanced Examples
Dynamic Client Configuration
Parallel Data Fetching
Request Deduplication
Next.js automatically deduplicates identical fetch requests:TypeScript Types
Best Practices
Create a centralized client instance
Create a centralized client instance
Create a single client instance in a shared module to ensure consistent configuration:
Use Server Components for data fetching
Use Server Components for data fetching
Prefer Server Components for initial data loading to reduce client bundle size:
Handle errors gracefully
Handle errors gracefully
Always check for errors and provide fallbacks:
Leverage caching strategically
Leverage caching strategically
Use appropriate caching strategies based on data freshness requirements:
Next Steps
Fetch Client
Learn about the underlying Fetch client
Server Components
Use in React Server Components
Caching
Configure caching strategies
Authentication
Set up API authentication