What's next for api-client, and what I'd do differently
The last post in the series — where the package is headed, and an honest look at what I'd change if I were starting it over today.
22 posts
The last post in the series — where the package is headed, and an honest look at what I'd change if I were starting it over today.
Not a generic FAQ — the specific, confusing failures I ran into using this package myself, and what the actual fix turned out to be each time.
A scannable reference for createClient, defineModule, ctx.request, and every config key covered across this series — for when you know what you need and just want the shape.
The mock client swaps in for your real one with the same method signatures, so your components and tests don't know or care the network isn't real.
The same client, wired up correctly in four different environments — and the one Next.js mistake that quietly defeats the RPC bridge from the last two posts.
Deny-by-default is one layer. Here's every other threat the bridge is built to handle — prototype pollution, CSRF, and the line between what it secures and what your code still has to.
Import your normal API client into a client component and check the Network tab. This is the architecture that stops that from happening.
Cache invalidation from the pipeline and TanStack Query's own cache used to be two separate systems that didn't know about each other. Here's how the integration package fixes that.
Generated types describe what the spec said at generation time. This is what catches the gap between that and what the backend actually returns today.
generate, watch, validate, diff — the four CLI commands that keep your client's types honest against a real, changing backend spec.
Adding a trace header to every outgoing request shouldn't mean editing forty methods. Hooks and events are the two different tools for two different jobs.
A network timeout and a 404 are not the same problem and shouldn't be handled with the same catch block. Here's the typed error hierarchy, and when safeMode is worth the tradeoff.
How to resolve the right tenant ID per request in a shared SSR client — and why ambient context beats passing tenantId through every function call.
Four small resilience features that, combined, are the difference between an app that shrugs off a bad network and one that falls apart on a train.
Three cache strategies, why the cache key includes more than the URL, and how to invalidate cleanly after a mutation.
Bearer, cookie, API key, OAuth2 — and the one bug almost every hand-rolled auth layer has: four parallel requests triggering four token refreshes at once.
One flaky endpoint needs a longer timeout. Here's how to give it one without touching your global config or copy-pasting settings everywhere.
One flaky endpoint needs a longer timeout. Here's how to give it one without touching your global config or copy-pasting settings everywhere.
Most methods just return .data and move on. Here's what's actually inside ApiResponse, and how to combine multiple endpoints into one clean method.
Most methods just return .data and move on. Here's what's actually inside ApiResponse, and how to combine multiple endpoints into one clean method.
Before touching config options, understand the client, the modules, and the pipeline — the three ideas everything else in api-client is built on.
Every project I ship ends up with the same auth-retry-cache logic copy-pasted and slightly broken. Here's why I finally turned that pattern into a real package.