@talosjs/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 it earns its place
The case forFetcher is calling REST APIs that return JSON when you’d rather not repeat the same fetch boilerplate. One instance carries a base URL, an auth token, and a language header across every request it makes, and the configuration methods chain. File uploads, request aborting, and cloning come along with it.
For a one-off, non-JSON request, the native fetch is already enough.