When to Mount APIs
Mount APIs as CLIs when you:- Want to expose HTTP endpoints via CLI without writing separate handlers
- Need a unified interface for both web and CLI access
- Have an existing API and want instant CLI support
- Want to test API endpoints directly from the command line
Basic API Mounting
import { Hono } from 'hono'
const app = new Hono()
.get('/users', (c) => c.json({ users: [{ id: 1, name: 'Alice' }] }))
.post('/users', async (c) => c.json({ created: true, ...(await c.req.json()) }, 201))
import { Cli } from 'incur'
Cli.create('my-cli', {
description: 'My CLI',
fetch: app.fetch, // Mount the entire API
}).serve()
curl-Style Translation
incur translates CLI arguments to HTTP requests using curl-style conventions:Path Segments
Bare arguments become path segments:HTTP Methods
Use-X or --method to set the HTTP method:
Default method is
GET, or POST if a body is provided via -d or --data.Request Body
Use-d, --data, or --body to send a request body:
Headers
Use-H or --header to set headers:
Query Parameters
Any unknown--flag becomes a query parameter:
Framework Examples
Hono
Bun
Deno
Elysia
Mounting as Commands
Mount APIs on specific commands instead of the root:Base Path
Specify a base path to strip from CLI arguments:OpenAPI Integration
Pass an OpenAPI spec alongsidefetch to generate typed subcommands:
Generated Commands
incur extracts:- Command names from
operationId - Descriptions from
summaryordescription - Arguments from path parameters
- Options from query parameters and request body properties
Typed Subcommands
Each operation becomes a typed command:OpenAPI integration uses
@readme/openapi-parser to resolve all $ref pointers automatically. The spec can be passed as a plain object or imported JSON.Example OpenAPI App
Usage
Fetch Handler Help
Fetch handlers have specialized help text:Streaming Responses
APIs that return NDJSON streams are automatically handled:Streaming only works for responses with
content-type: application/x-ndjson. Each line is parsed as JSON and output incrementally.Error Handling
HTTP error responses are automatically converted to CLI errors:Best Practices
Use OpenAPI for Complex APIs
For APIs with many endpoints, use OpenAPI to get typed commands automatically:Mount on Subcommands
Keep the root clean by mounting APIs on subcommands:Provide Base Paths
UsebasePath to simplify CLI arguments:

