mizu contract command helps you work with service contracts. A contract defines what your API can do - the methods, their inputs, and their outputs. This command lets you discover, explore, call methods, view schemas, and export specifications like OpenAPI directly from the command line.
What is a Service Contract?
A service contract defines the interface of your API:- What methods are available
- What data each method accepts
- What data each method returns
contract template, your services are automatically discoverable. The mizu contract command lets you explore and interact with these APIs from the command line.
Quick Examples
Subcommands
| Command | Description |
|---|---|
mizu contract ls | List all services and methods |
mizu contract show | Show details about a method |
mizu contract call | Call a method |
mizu contract spec | Export API specification |
mizu contract types | List available types and schemas |
Setting the Server URL
By default, commands connect tohttp://localhost:8080. You can change this in several ways:
--url flag > MIZU_URL environment variable > default.
mizu contract ls
Lists all services and their methods.Usage
Flags
| Flag | Description |
|---|---|
--url <string> | Server URL |
--all | Include deprecated methods |
--json | Output as JSON |
Example
JSON Output
mizu contract show
Shows detailed information about a specific method.Usage
Flags
| Flag | Description |
|---|---|
--url <string> | Server URL |
--schema | Show full JSON schema |
--json | Output as JSON |
Example
Show Full Schema
mizu contract call
Calls a method with input data and returns the result.Usage
Input Formats
| Format | Example | Description |
|---|---|---|
| JSON string | '{"title":"Buy milk"}' | Inline JSON |
| File | @input.json | Read from file |
| Stdin | - | Read from stdin |
Flags
| Flag | Description |
|---|---|
--url <string> | Server URL |
--id <string> | Path parameter ID (for REST) |
--timeout <duration> | Request timeout (default: 30s) |
-H, --header <key:value> | Add request header (repeatable) |
--raw | Output raw response |
Examples
Call with inline JSON:Error Output
If the call fails:mizu contract spec
Exports the API specification in OpenAPI or OpenRPC format.Usage
Flags
| Flag | Description |
|---|---|
--url <string> | Server URL |
--format <string> | Output format (openapi, openrpc) |
--service <string> | Export specific service only |
--pretty | Pretty print JSON |
-o, --output <file> | Write to file |
Examples
Export OpenAPI spec:mizu contract types
Lists all types and their schemas.Usage
Flags
| Flag | Description |
|---|---|
--url <string> | Server URL |
--schema | Show full JSON schema |
--json | Output as JSON |
List All Types
Show Specific Type
Show Full Schema
Discovery Methods
The CLI tries multiple methods to discover your API:- JSON-RPC Discovery - Calls
rpc.discovermethod - OpenRPC Spec - Fetches
/openrpc.json - OpenAPI Spec - Fetches
/openapi.json - Contract Endpoint - Fetches
/_contract
Practical Workflows
Explore a New API
Generate Client Documentation
Test During Development
CI/CD Integration
Error Messages
Cannot Discover Contract
- Server is not running
- Server doesn’t expose discovery endpoints
- Wrong URL
- Make sure your server is running (
mizu dev) - Verify the URL is correct
- Check that you’re using the
contracttemplate
Method Not Found
mizu contract ls to see available methods.
Missing Required Input
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (API error, network error) |
| 2 | Usage error (missing arguments) |