Skip to content

Repository files navigation

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-client

Usage

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:

  1. Regenerates src/ from the live OpenAPI spec
  2. Sets the version to 0.0.0-{commit-sha}
  3. Builds and publishes to npm

About

A TypeScript api client for connecting to the PieFed API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages