Basic Usage
Pass an OpenAPI spec alongside thefetch property to generate typed subcommands:
Generated Command Structure
incur parses your OpenAPI spec and generates commands with:- Operation ID as command name —
operationIdbecomes the command name - Path parameters as arguments — path params like
{id}become positional arguments - Query parameters as options — query params become
--flagoptions - Request body as options — JSON body properties become
--flagoptions - Descriptions from spec —
summaryanddescriptionfields flow through to help text
Example Commands
Without OpenAPI
You can also mount a fetch handler without a spec. All argv tokens are interpreted as path segments and curl-style flags:Curl-style Flags
When usingfetch without OpenAPI, incur supports:
| Flag | Description |
|---|---|
-X, --method <METHOD> | HTTP method (default: GET, POST if body present) |
-H, --header "Key: Val" | Set a request header (repeatable) |
-d, --data <json> | Request body (implies POST) |
--body <json> | Request body (implies POST) |
--<key> <value> | Query string parameter |
Mounting as Commands
You can mount fetch handlers onto specific commands instead of the root:Base Path
UsebasePath to prefix all requests:
Framework Compatibility
incur works with any framework that exposes a Web Fetch API handler:Type Safety
incur resolves all$ref pointers in your OpenAPI spec and converts JSON Schema types to Zod schemas with automatic coercion for path and query parameters (which arrive as strings from argv).
Error Handling
HTTP errors are automatically converted to incur error envelopes:message field, it’s used as the error message. Otherwise, the entire body or a generic HTTP {status} message is shown.
