Skip to main content
The contract template creates a service based on transport-neutral contracts. A β€œcontract” in this context means a formal definition of what your API can do - like a menu at a restaurant. You define the methods once as Go code, and the framework automatically creates multiple ways to call them (REST, JSON-RPC) plus generates documentation (OpenAPI).

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

Test the different protocols:

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:
Both transports call the same method:

Automatic Documentation

OpenAPI spec is generated from your Go types:
Generates:

Type Safety

Everything is strongly typed:

Discoverable

Clients can discover available methods:

Project Structure

Available Transports

CLI Integration

Use mizu contract to interact with your service:

When to Use Contract vs API Template

Next Steps

Project Structure

Understand every file in detail

Tutorial

Build a contract-based service