Introduction
@mrzr/api-client is a zero-dependency TypeScript fetch client that handles browser auth for you: token refresh, Web Worker token isolation and cross-tab sync.
@mrzr/api-client is a small HTTP client built on fetch. You make requests; it handles the tokens.
import { createClient } from "@mrzr/api-client";
export const api = createClient({ baseUrl: "https://api.example.com" });
await api.login({ email, password }); // tokens are stored for you
const { data } = await api.get<User[]>("/users"); // Authorization is attached for youWhat it does for you
| When… | The client… |
|---|---|
| The access token expires while 20 requests are in flight | Sends one refresh request, then retries all 20 |
| An injected script looks for the token | Can't find it: requests run in a Web Worker and the token stays there |
| The user logs out in one tab | Logs out every other tab too |
| The token is about to expire | Refreshes it before the next request fails |
| The user leaves the page | Can cancel the requests that page started |
No runtime dependencies. Works in browsers, Node 20+, Deno, Bun and Cloudflare Workers.
Is it for you?
Use it if you have a browser app that logs users in and calls your own API, and you're tired of writing refresh-token interceptors.
If you only need a thin fetch wrapper with retries, ky is a better fit. This client has no retry option.
Next
- Quick start: set it up in five minutes
- Live demo: watch the refresh and cancellation happen in your browser