api
@mrzr/api-client
Getting Started

Installation

How to install @mrzr/api-client across npm, pnpm, yarn, and bun

npm install @mrzr/api-client
# or
pnpm add @mrzr/api-client
yarn add @mrzr/api-client
bun add @mrzr/api-client

The package ships ESM + CJS + TypeScript declarations and has no runtime dependencies.


Requirements

Any runtime with fetch and AbortController:

RuntimeMinimum
Node.js20 (enforced via engines)
Chrome / Edge80+
Firefox78+
Safari14+
Deno1.x+
Bun1.x+
Cloudflare Workers

Optional capabilities degrade gracefully when missing:

CapabilityUsed forIf missing
Worker + Blob + URL.createObjectURLWorker isolationFalls back to the identical main-thread implementation
BroadcastChannelMulti-tab syncSingle-tab behaviour
AbortSignal.anyCombining timeout + user signalManual signal linking fallback
localStorage / sessionStoragePersistent storageReads/writes become no-ops (Safari private mode is handled)

Module formats

EntryFile
ESMdist/index.js
CJSdist/index.cjs
Types (ESM)dist/index.d.ts
Types (CJS)dist/index.d.cts
// ESM / TypeScript / bundlers
import { createClient } from "@mrzr/api-client";
// CommonJS
const { createClient } = require("@mrzr/api-client");
<!-- No build step -->
<script type="module">
  import { createClient } from "https://esm.sh/@mrzr/api-client";
</script>

The package is marked "sideEffects": false, so bundlers tree-shake anything you don't import.


TypeScript setup

No extra @types package is needed. For the best experience use:

{
  "compilerOptions": {
    "moduleResolution": "bundler", // or "node16" / "nodenext"
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "strict": true
  }
}

moduleResolution: "node" (the legacy default) also resolves correctly — the package exposes main/module/types alongside exports.


Framework installation notes

Next.js

No configuration needed. On the server, worker mode disables itself automatically. In server components and route handlers, prefer creating a short-lived client and calling destroy() — see [[Framework Recipes]].

Vite / Nuxt / SvelteKit

No configuration needed. The worker is created from an inlined blob, so there is no worker file to host and no ?worker import to wire up.

Content Security Policy

Blob workers require worker-src blob: (or child-src blob:). If your CSP forbids it, the client catches the failure and silently runs on the main thread instead — nothing breaks, you just lose isolation. To be explicit about it, set worker: false.

Content-Security-Policy: worker-src 'self' blob:;

React Native

fetch and AbortController exist, so requests work. Worker, BroadcastChannel and localStorage do not — pass worker: false, multiTab: false, and a custom storage adapter backed by AsyncStorage or expo-secure-store.


Verifying the install

import { createClient } from "@mrzr/api-client";

const api = createClient({ baseUrl: "https://httpbin.org" });
console.log(api.isWorker);            // true in a browser, false on the server
console.log((await api.get("/get")).status); // true
api.destroy();

Next: [[Quick Start]]

On this page