Type-Safe API Client
Shapeless provides an end-to-end type-safe API client that knows your entire backend router. This means TypeScript can infer exactly what your API expects and returns, helping you catch errors early.
1. Client Setup
Create your API client by passing it the AppRouter
type from your backend. Adjust the base URL depending on your deployment environment:
src/app/shapeless-client.ts
2. Making API Calls
Use the client anywhere in your app with full type safety. Here’s a simple example calling a post.recent
endpoint:
3. Using with React Query
Because the client is just a typed fetch
wrapper, you can use it with any state management or data fetching library. For example, with React Query:
You can swap React Query for Zustand, Jotai, Redux, or anything else — it just works.
This type-safe client keeps your frontend and backend tightly integrated, reducing bugs and improving DX.