@blorp-labs/piefed-api-client
v0.0.0-906d602
Published
Typed TypeScript client for the PieFed API, generated from the OpenAPI spec
Readme
piefed-api-client
Typed TypeScript client for the PieFed API, automatically generated from the OpenAPI spec.
Includes:
- TypeScript interfaces/types (
src/schemas/) - Native
fetch-based API functions (src/client/) - Zod validation schemas (
src/zod/)
Installation
pnpm add @blorp-labs/piefed-api-clientUsage
Basic
import { createClient } from '@blorp-labs/piefed-api-client';
const client = createClient('https://piefed.social');
const site = await client.getApiAlphaSite();With authentication
const client = createClient('https://piefed.social', {
headers: { Authorization: 'Bearer <token>' },
});With default fetch options
Any RequestInit option (except body and method) can be set as a default:
const client = createClient('https://piefed.social', {
cache: 'no-store',
headers: { Authorization: 'Bearer <token>' },
});Per-call options override the defaults; headers are merged.
Multiple instances
const a = createClient('https://instance-a.com');
const b = createClient('https://instance-b.com');Error handling
Errors throw an ApiError with .status and .data:
import { createClient, ApiError } from '@blorp-labs/piefed-api-client';
try {
const site = await client.getApiAlphaSite();
} catch (e) {
if (e instanceof ApiError) {
console.error(e.status, e.data);
}
}Zod schemas
Zod schemas are exported from the /zod subpath:
import { getApiAlphaSiteQueryParams } from '@blorp-labs/piefed-api-client/zod';Development
Requires corepack (ships with Node 16+).
corepack enable
pnpm install
pnpm generate # regenerate src/ from OpenAPI spec
pnpm build # compile TypeScript → dist/Automation
A GitHub Actions workflow triggers on every push to main. It:
- Regenerates
src/from the live OpenAPI spec - Sets the version to
0.0.0-{commit-sha} - Builds and publishes to npm
