Skip to content

Installation

Requirements

HTTP Guardian targets modern TypeScript projects that provide fetch.

Topic Expected Value Why
Node >= 22 CI and development runtime aligned with current packages.
TypeScript Modern module resolution Public declarations must be resolved by the consumer.
Browser fetch, Headers, AbortController Used by the HTTP transport and timeouts.
RxJS Optional Required only with @cedvict/http-guardian-rx.

Install the Core

npm i @cedvict/http-guardian

Add RxJS only when the application needs it

npm i @cedvict/http-guardian-rx rxjs

The RxJS adapter does not change the parsing contract. It exposes the same results as an Observable, which avoids maintaining two error models in an Angular application.

Add plugins case by case

npm i @cedvict/http-guardian-plugin-retry
npm i @cedvict/http-guardian-plugin-timeout
npm i @cedvict/http-guardian-plugin-logger
npm i @cedvict/http-guardian-plugin-sentry
npm i @cedvict/http-guardian-plugin-otel
npm i @cedvict/http-guardian-plugin-rate-limit

Every plugin must match an explicit policy. Installing a package is not enough: it must also be passed through plugins or guards according to its contract.

First Client

import {
  bearerAuth,
  createApiParserRestClassic,
  createHttpClient,
  memoryCache
} from "@cedvict/http-guardian";

type User = { id: string; email: string };

export const api = createHttpClient({
  baseUrl: "https://api.example.com/v1",
  auth: bearerAuth(() => localStorage.getItem("token")),
  parser: createApiParserRestClassic(),
  cache: memoryCache({ maxEntries: 500 })
});

const result = await api.get<User>("/me", {
  cache: { ttlMs: 30_000, tags: ["me"] }
});

if (result.ok) {
  console.log(result.data.email);
} else {
  console.error(result.errors);
}

Do not hide configuration

Even a public API must declare auth: noAuth(). A silent absence of auth makes refresh guards, diagnostics, and per-request exceptions more ambiguous.