@ooneex/fetcher wraps the native fetch API in a small Fetcher class. It manages a base URL, typed headers, authentication tokens, and request bodies, automatically serializing JSON and parsing JSON responses. Every helper returns a typed response, and configuration methods are chainable.
Installation
Add the package with Bun.Usage
Create aFetcher, optionally with a base URL, then call the verb helpers. Request bodies passed as plain objects are JSON-serialized automatically and responses are parsed as JSON.
Basic requests
Authentication and headers
Header and auth setters are chainable and persist across requests made by the same instance.Uploading files
upload sends multipart/form-data, clearing the JSON content type so the boundary is set correctly.
Aborting and cloning
When to use it
- You call external or internal REST APIs that return JSON and want typed responses without writing
fetchboilerplate each time. - You need a single client that carries a base URL, auth token, and language header across many requests.
- You want simple file uploads, request aborting, and chainable configuration out of the box.
- Not needed for one-off, non-JSON requests where the native
fetchis already sufficient.