When to Use This Template
Use the contract template when:- Multiple protocols needed - REST for web clients, JSON-RPC for internal services
- API-first design - Define contracts before implementation
- Auto-generated docs - OpenAPI specs from your code
- Clean architecture - Business logic separate from transport
What You Get
A complete service with:- Service contracts - Plain Go structs with typed methods
- REST transport - RESTful HTTP endpoints
- JSON-RPC transport - JSON-RPC 2.0 endpoint
- OpenAPI spec - Auto-generated at
/openapi.json - Discovery endpoint - List available methods
Quick Start
How Contracts Work
1. Define a Service
2. Register with Contract System
3. Mount Transports
Benefits
Write Once, Expose Multiple Ways
Your business logic is in plain Go methods:Automatic Documentation
OpenAPI spec is generated from your Go types:Type Safety
Everything is strongly typed:Discoverable
Clients can discover available methods:Project Structure
Available Transports
| Transport | Endpoint | Use Case |
|---|---|---|
| REST | /api/* | Web clients, mobile apps |
| JSON-RPC | / (POST) | Internal services, RPC clients |
| OpenAPI | /openapi.json | Documentation, code generation |
| OpenRPC | /openrpc.json | JSON-RPC documentation |
CLI Integration
Usemizu contract to interact with your service:
When to Use Contract vs API Template
| Aspect | API Template | Contract Template |
|---|---|---|
| Protocols | REST only | REST + JSON-RPC |
| Documentation | Manual | Auto-generated |
| Type safety | At boundaries | Throughout |
| Complexity | Lower | Higher |
| Best for | Simple APIs | Multi-protocol services |