@vielzeug/courier
v26.10.18
Published
Typed HTTP client with bounded structured-key caching, prefetching, immutable middleware, and structured errors
Readme
@vielzeug/courier
Typed HTTP client with bounded structured-key caching, prefetching, immutable middleware, and structured errors
Installation
pnpm add @vielzeug/courier
npm install @vielzeug/courier
yarn add @vielzeug/courierQuick Start
import { createCourier, withBearerAuth } from '@vielzeug/courier';
type User = { id: number; name: string };
const courier = createCourier({
baseUrl: 'https://api.example.com',
middleware: [withBearerAuth('token')],
});
const usersKey = ['accounts', 'account-1', 'users'] as const;
await courier.prefetch<User[]>('/users', { cache: { key: usersKey } });
const users = await courier.get<User[]>('/users', { cache: { key: usersKey } });
const created = await courier.post<User>('/users', { body: { name: 'Ada' } });
courier.invalidateCache(['accounts', 'account-1', 'users']);
courier.dispose();Features
CourierHttpError.problem: parsed RFC 9457 problem details (application/problem+json) with the HTTP status kept authoritative.
Documentation
License
MIT © Helmuth Saatkamp: part of the Vielzeug monorepo.
