Type-Safe API Client
One of the best features of JSandy is its end-to-end type safety 😎. Let's see how to make type-safe API calls - so TypeScript knows exactly what data to expect from our server.
1. Client Setup
Create a type-safe client that knows about all your API routes by passing it the AppRouter
type - the type of your entire backend:
lib/client.ts
2. Client Usage
You can now make API calls from anywhere in your application with full type-safety 🎉.
app/page.tsx
3. Example with React Query
JSandy's client works anywhere and with any state manager because it's simply a type-safe fetch
wrapper. For example, it pairs perfectly with React Query:
app/page.tsx
You can use the client with any other state manager you prefer, such as Zustand, Jotai, or Redux. JSandy does not care 🤷♂️.