Fetcher
Type-safe API data fetching with RPC-style interface
The VitNode fetcher provides a type-safe RPC (Remote Procedure Call) style interface for making API requests. It simplifies data fetching by providing strong typing and a consistent API across your application.
Server-side only
The fetcher()
function can only be used on the server-side. Client-side
usage is not supported.
Getting Started
First, import the required dependencies:
Make your first API call:
The fetcher returns a standard Response object, just like the native fetch
API. This makes it familiar and easy to work with.
Advanced Features
Caching Responses
You can leverage Next.js caching by passing cache options:
Cookie Management
When working with authentication or sessions, you might need to handle cookies. React Server Components have special considerations for cookie handling:
Cookie Handling
Cookie saving is only supported for requests that return a 2xx status code.
Here's how to enable cookie handling for a sign-in request: