@gcmdev/faxios
v0.4.0
Published
Promise based, web-standard fetch HTTP client for the browser, Node.js, Deno and Bun
Downloads
323
Maintainers
Readme
faxios
Promise based HTTP client for the browser, Node.js, Deno, and Bun — a TypeScript-first fork of axios.
Features
- Uses the web-standard
fetchAPI in every runtime: browser, Node.js, Deno, and Bun. - Promise API with onion-style
.use()middleware and built-in plugins for retries, bearer auth, header, query and cookie credentials, credential refresh, forwarding gateways and timing. - Request and response data transforms, with automatic JSON handling.
- Serializes objects to
multipart/form-dataorapplication/x-www-form-urlencoded. - Cancellation with
AbortSignal. - Request and response validation with any Standard Schema v1 library (Zod, Valibot, ArkType). A failed
responseSchemakeeps the rejected body onerror.response.data. - Strictly typed request
headers, with suggestions for common header names andContent-Typevalues. - Typed endpoint builders:
faxios.define()andfaxios.route(). - Client-side protection against Cross-Site Request Forgery.
- ESM-only, with TypeScript definitions included (TypeScript 5.4 or greater).
Installing
npm install @gcmdev/faxiospnpm add @gcmdev/faxiosExample
import faxios from "@gcmdev/faxios";
// Outside the browser a relative URL needs a baseURL.
const api = faxios.create({ baseURL: "https://example.test" });
const { data: user } = await api.get("/user", {
params: { ID: 12345 },
timeout: 5000,
});
const response = await api.post("/user", {
firstName: "Fred",
lastName: "Flintstone",
});Add behaviour to every request with .use(). Keep the instance it returns: only that value is typed with the plugin's options.
import faxios from "@gcmdev/faxios";
import { retry } from "@gcmdev/faxios/plugins/retry";
const api = faxios.create({ baseURL: "https://example.test" }).use(retry());
const { data } = await api.get("/user", { headers: { Accept: "application/json" } });Documentation
The full documentation is at https://adrianbrowning.github.io/faxios/.
- First steps
- Request config
- Error handling
- Middleware
- Plugins
- Migrating from interceptors
- Schema validation
- Typed endpoints:
define() - Route builder:
route() - Headers
- TypeScript
Contributing
See CONTRIBUTING.md.
Credits
faxios is a fork of axios. axios is heavily inspired by the $http service in AngularJS, and provides a standalone $http-like service for use outside AngularJS.
