# Introduction (/docs)



`@mrzr/api-client` is a small HTTP client built on `fetch`. You make requests; it handles the tokens.

```ts
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 you
```

## What it does for you [#what-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? [#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](https://github.com/sindresorhus/ky) is a better fit. This client has no retry option.

## Next [#next]

* [Quick start](/docs/quick-start): set it up in five minutes
* [Live demo](/docs/demo): watch the refresh and cancellation happen in your browser
