-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
npm install @mrzr/api-client
# or
pnpm add @mrzr/api-client
yarn add @mrzr/api-client
bun add @mrzr/api-clientThe package ships ESM + CJS + TypeScript declarations and has no runtime dependencies.
Any runtime with fetch and AbortController:
| Runtime | Minimum |
|---|---|
| Node.js | 20 (enforced via engines) |
| Chrome / Edge | 80+ |
| Firefox | 78+ |
| Safari | 14+ |
| Deno | 1.x+ |
| Bun | 1.x+ |
| Cloudflare Workers | ✅ |
Optional capabilities degrade gracefully when missing:
| Capability | Used for | If missing |
|---|---|---|
Worker + Blob + URL.createObjectURL
|
Worker isolation | Falls back to the identical main-thread implementation |
BroadcastChannel |
Multi-tab sync | Single-tab behaviour |
AbortSignal.any |
Combining timeout + user signal | Manual signal linking fallback |
localStorage / sessionStorage
|
Persistent storage | Reads/writes become no-ops (Safari private mode is handled) |
| Entry | File |
|---|---|
| ESM | dist/index.js |
| CJS | dist/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.
No extra @types package is needed. For the best experience use:
moduleResolution: "node" (the legacy default) also resolves correctly — the package exposes main/module/types alongside exports.
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.
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.
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:;
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.
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
Getting started
Requests
Authentication
Advanced
- Web Worker Isolation
- Multi-Tab Sync
- WebSockets and Socket.io
- Plugins
- Logging and Observability
- Security Model
Reference
Guides
{ "compilerOptions": { "moduleResolution": "bundler", // or "node16" / "nodenext" "lib": ["ES2020", "DOM", "DOM.Iterable"], "strict": true } }