@alt-stack/http-client-fetch
v1.5.1
Published
Type-safe HTTP client using native fetch API
Readme
@alt-stack/http-client-fetch
Typed Zod-backed HTTP client using the standard Fetch API. Successful and documented error responses include the native Response as raw.
Install
pnpm add @alt-stack/http-client-fetch zodUse Zod 4 and a runtime with fetch, Response, Headers, and AbortController (Node.js 18+, modern browsers, or Bun).
Quick use
import { createApiClient } from "@alt-stack/http-client-fetch";
import { Request, Response } from "./generated-api.js";
const api = createApiClient({
baseUrl: "http://127.0.0.1:3000",
Request,
Response,
fetchOptions: { credentials: "include" },
});
const result = await api.get("/users/{id}", { params: { id: "u_1" } });
if (result.success) console.log(result.body, result.raw.status);Request and Response can be generated by @alt-stack/zod-openapi. Fetch options cannot override the executor-owned method, headers, body, or signal.
