Installation
npm install @tahanabavi/typefetch zodOr with Yarn:
yarn add @tahanabavi/typefetch zodOr with pnpm:
pnpm add @tahanabavi/typefetch zodzod is the only peer dependency. The core itself has zero runtime
dependencies.
Optional packages
Install only what you use — nothing below is bundled unless you register it.
| Package | Add when you need |
|---|---|
@tahanabavi/typefetch-graphql | GraphQL routes |
@tahanabavi/typefetch-grpc | gRPC / Connect routes |
@tahanabavi/typefetch-encryption | encryptionMiddleware |
@tahanabavi/typewire-cli | the typewire command |
Quick Start
import { z } from "zod";
import { ApiClient } from "@tahanabavi/typefetch";
const contracts = {
user: {
getUser: {
method: "GET",
path: "/users/:id",
auth: true,
request: z.object({
path: z.object({
id: z.string(),
}),
}),
response: z.object({
id: z.string(),
name: z.string(),
}),
},
},
} as const;
const client = new ApiClient(
{
baseUrl: "https://api.example.com",
tokenProvider: async () => "your-token",
},
contracts,
);
client.init();
const api = client.modules;
const user = await api.user.getUser({
path: { id: "123" },
});
console.log(user.name);