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
Step 2: Create the Notes Service
Create the service directory:service/notes/notes.go:
Step 3: Implement the Methods
Add the methods toservice/notes/notes.go:
Step 4: Register the Service
Updateapp/server/server.go:
Step 5: Test the API
Restart the server:Test via REST
Test via JSON-RPC
Test via CLI
View OpenAPI Spec
http://localhost:8080/openapi.json in your browser.
Step 6: Add Search Method
Letβs add a search capability. Add toservice/notes/notes.go:
What You Learned
- Service contracts - Define business logic as Go methods
- Transport-neutral - Same code works for REST and JSON-RPC
- Auto-discovery - Methods are automatically exposed
- OpenAPI generation - Documentation from your code
- 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