@pumicejs/client
v0.0.10
Published
TypeScript API client generator for pumice.js APIs
Maintainers
Readme
@pumicejs/client
Type-safe client generator for pumice.js APIs.
This package reads the route manifest exposed by ClientGenerationPlugin (default GET /@client) and generates a nested TypeScript client:
- static segments as nested objects
- dynamic segments as
.$(param) - typed
.get(),.post(),.put(),.patch(),.delete(),.options()calls
Install
npm install @pumicejs/clientRequires Node.js >=18.
Generate a client
npx pumice-client generate --url http://localhost:3000 --output ./generated/api-client.tsCLI options
-u, --url <url>API base URL (defaulthttp://localhost:3000)-o, --output <path>Output file path (default./generated/pumice-api-client.ts)-m, --manifest-path <path>Manifest endpoint path (default/@client)--no-formatSkip Prettier formatting-d, --debugEnable debug logs--allow-request-specific-headersAdd optionalheadersto generated method options--export-route-typesExport route-specific aliases likePmUsersByIdGetResponseBody--type-prefix <prefix>Prefix exported route helper types (defaultPm)
Generated exports
Generated client files intentionally export only:
apicreateClient- prefixed route helper types like
PmRouteType/PmRoutePath
Route-specific request/response types stay internal to keep the public export surface small.
If you want those aliases exported (e.g. PmUsersByIdGetResponseBody), generate with --export-route-types.
Package exports
@pumicejs/client exports a minimal runtime API:
createClientFactoryClientOptionsRequestExecutorProxyFnRequestErrorRequestErrorInfo
Runtime usage
import { api, createClient } from "./generated/api-client";
const users = await api.users.get();
const oneUser = await api.users.$(123).get();
const authed = createClient({
baseUrl: "https://api.example.com",
headers: {
authorization: "Bearer <token>",
},
});
await authed.users.post({
body: { name: "Ada" },
});