Typed, inspectable HTTP requests on top of fetch.
Build requests as immutable values, preview them, render cURL, validate responses, then execute.
Install · Example · Model · Features · Runtime · Guides
npm install avirximport { avirx } from 'avirx';
const Book = {
parse(input: unknown): { id: string; title: string } {
return input as { id: string; title: string };
},
};
const api = avirx('https://api.example.com');
const request = api
.get('/books/{id}')
.path({ id: 'book_123' })
.query({ include: ['author', 'reviews'] });
console.log(await request.preview());
console.log(await request.curl());
const book = await request.as(Book);Avirx treats requests as values. Build a request once, then inspect, clone, or execute it without hidden mutation.
const result = await api
.get('/books/{id}')
.path({ id: 'missing' })
.result(Book);
if (!result.ok) {
console.log(result.status);
}- Immutable fluent request builders
- Typed path parameters from route strings
- Query, JSON body, multipart upload, and download helpers
- Runtime schema validation with any parser that exposes
parse - Result mode for expected HTTP failures
- Redacted preview and cURL output
- Auth, timeout, retry, hooks, cache, concurrency, and rate-limit policies
- Zero runtime dependencies
Avirx requires Node.js 18.17 or newer, or any runtime with compatible fetch, Request, Response, Headers, Blob, FormData, and AbortController APIs.