Getting Started
endpoint-fetcher is a lightweight, type-safe API client builder for TypeScript built on the Fetch API.
Installation
npm install endpoint-fetcherQuick Start
import { createApiClient, get, post, del } from 'endpoint-fetcher';
type User = { id: string; name: string; email: string };
type CreateUserInput = { name: string; email: string };
const api = createApiClient({
listUsers: get<void, User[]>('/users'),
getUser: get<{ id: string }, User>((input) => `/users/${input.id}`),
createUser: post<CreateUserInput, User>('/users'),
deleteUser: del<{ id: string }, void>((input) => `/users/${input.id}`),
}, {
baseUrl: 'https://api.example.com',
});
const users = await api.listUsers();
const user = await api.getUser({ id: '123' });
const newUser = await api.createUser({ name: 'Jane', email: 'jane@example.com' });Every call is fully typed β TypeScript infers inputs, outputs, and errors.
What endpoint-fetcher provides
- Type safety β Full TypeScript inference for inputs, outputs, and error shapes
- HTTP helpers β
get,post,put,patch,delfor defining endpoints - Groups β Organize endpoints hierarchically with shared hooks and base paths
- Hooks β Intercept requests/responses globally, per group, or per endpoint
- Plugins β Extend with caching, retries, and custom logic via official plugins
- Custom handlers β Override the default JSON behavior for files, streaming, etc.
Next Steps
- Basic Usage β Define endpoints, call them, handle responses
- Groups β Organize large APIs with nested groups and base paths
- Hooks β Add auth, logging, and error handling
- Plugins β Official cache and retry plugins