Testing without mocking fetch by hand, again
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.
20 posts
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.
URLSearchParams sends missing filters as the literal word 'undefined'. The truthy filter that seems to fix it then quietly drops page=0.
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.
Sharing one in-flight request between callers is a great speed trick. If the key only says what was asked for, and not who asked, the second user gets the first user's data. Here is a 30-line reproduction and the fix.
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.
new URL(path, baseURL) is not string joining. A leading slash wipes your base path, a missing trailing slash eats a segment, and the wrong path can send your auth token to someone else's server.
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.
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.