@mrzr/api-client

The fetch client that handles your auth tokens

You make requests. It attaches the token, refreshes it when it expires, keeps it away from page scripts and keeps your tabs logged in together. TypeScript, zero dependencies.

Get startedLive demo
$npm install @mrzr/api-client
import { createClient } from "@mrzr/api-client";export const api = createClient({ baseUrl: "https://api.example.com" });await api.login({ email, password });            // tokens stored for youconst { data } = await api.get<User[]>("/users"); // token attached, refreshed when needed

See it work

This runs the real package in your browser against a small demo API.

One refresh for many requests

Expire the token, then send 8 requests at the same time. Open DevTools → Network to watch it happen.

  1. 1.The access token is replaced with an expired one.
  2. 2.8 requests go out at once. The server answers each with 401.
  3. 3.The client pauses them and sends a single refresh request.
  4. 4.All 8 requests are retried with the new token and succeed.
GET #1 not sentGET #2 not sentGET #3 not sentGET #4 not sentGET #5 not sentGET #6 not sentGET #7 not sentGET #8 not sent

Refresh requests sent: –

What it handles