api-client

Build a typed TypeScript client for consuming Rango response-route JSON APIs without codegen.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill api-client-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-client
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/api-client
Command: npx skills add https://github.com/rangojs/rango --skill api-client-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Calling your own Rango JSON endpoints from another service or script normally means hand-writing fetch calls and URL building per call site, losing the type inference your response routes already provide. This Skill wraps that inference in a small typed client so first-party TypeScript code calls endpoints like typed functions. ## Core Features & Use Cases - Typed responses without codegen: Return types come from the handler via RouteResponse, so results are the bare payload type, not any. - Required, typed path params: Params are derived from the route pattern with ExtractParams, so a missing or misspelled param is a compile error instead of a runtime 404. - Typed error handling: Non-2xx responses throw an ApiError carrying the RFC 9457 ProblemDetails body. - Use Case: A background worker or browser client needs to call your /catalog/:productId endpoint; createApiClient gives autocomplete over route names and compile-time param checking with zero runtime dependency on the router. ## Quick Start Ask the AI to create a typed API client for your Rango response routes using the createApiClient helper with your urls patterns and generated route map.

Frequently Asked Questions about api-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a typed API client for my TypeScript backend routes?

Copy the createApiClient helper into your app and pass it your urls() patterns value plus the generated route map from rango generate. It returns a client where each route name exposes get, post, put, patch, and delete methods with typed params and responses.

How to get typed fetch responses without code generation?

Rango response routes already infer response types from the handler via RouteResponse. The createApiClient helper reuses that inference through type-only imports, so return types are resolved at compile time with no codegen or runtime dependency.

Can I use this API client in the browser or a worker?

Yes. The helper imports only types from @rangojs/router, which are erased at build time, and builds URLs itself instead of using the server-only createReverse. It runs anywhere fetch is available: browser, worker, or server.

Are request bodies and search params typed in the client?

No. Only path params are route-typed via ExtractParams. Search is a generic Record of string, number, or boolean, and body is unknown serialized to JSON. Typed input requires a declared schema layer, which is intentionally out of scope.

What happens when the API returns an error response?

Non-2xx responses throw an ApiError carrying the HTTP status and the parsed RFC 9457 ProblemDetails body. You can catch it, check err.status, and read err.problem.code or err.problem.detail with full typing.

Can third-party consumers use this typed client?

No. The client is TypeScript-only and needs your route types. External consumers in any language use the plain wire directly: bare JSON on success and application/problem+json on error, with no client required.