Skip to main content
In this tutorial, you’ll build a notes service that exposes both REST and JSON-RPC endpoints, with automatic OpenAPI documentation. The magic of contracts is that you write your business logic once, and it works through multiple protocols automatically - no duplicate code.

What We’re Building

A notes API with:
  • Create, list, get, update, delete operations
  • REST endpoints at /api/notes/*
  • JSON-RPC endpoint at /
  • OpenAPI spec at /openapi.json

Step 1: Create the Project

Verify it works:

Step 2: Create the Notes Service

Create the service directory:
Create service/notes/notes.go:

Step 3: Implement the Methods

Add the methods to service/notes/notes.go:

Step 4: Register the Service

Update app/server/server.go:

Step 5: Test the API

Restart the server:

Test via REST

Test via JSON-RPC

Test via CLI

View OpenAPI Spec

Or open http://localhost:8080/openapi.json in your browser.

Step 6: Add Search Method

Let’s add a search capability. Add to service/notes/notes.go:
Add the import at the top:
Test it:

What You Learned

  1. Service contracts - Define business logic as Go methods
  2. Transport-neutral - Same code works for REST and JSON-RPC
  3. Auto-discovery - Methods are automatically exposed
  4. OpenAPI generation - Documentation from your code
  5. CLI integration - Test services from command line

Key Takeaways

  • Separation of concerns - Business logic in services, transport in setup
  • Type safety - Strongly typed inputs and outputs
  • Consistency - Same API via multiple protocols
  • Discoverability - Clients can explore your API

Next Steps

Contract Concepts

Learn more about the contract system

Web Template

Build server-rendered web apps