What Is a Transport?
Think of a transport like a translator at the United Nations. The speaker (your service) gives the same message, but each translator converts it into a language their audience understands. In Contract terms:- Your service is the speaker - it has the business logic
- Transports are the translators - they convert requests/responses
- Clients are the audience - browsers, apps, AI assistants, etc.
Available Transports
Contract supports three transports plus documentation generation:| Transport | What It Is | Best For |
|---|---|---|
| REST | Traditional HTTP API | Web apps, mobile apps, curl |
| JSON-RPC | Remote procedure calls over HTTP | Batch operations, microservices |
| MCP | Model Context Protocol | AI assistants like Claude |
| OpenAPI | API documentation standard | Docs, code generation |
Decision Guide: Which Transport Should I Use?
Use this flowchart to pick the right transport for your use case:Detailed Comparison
Feature Comparison
| Feature | REST | JSON-RPC | MCP |
|---|---|---|---|
| HTTP Methods | GET/POST/PUT/DELETE | POST only | POST only |
| Batch Requests | No | Yes | No |
| Cacheable | Yes (GET requests) | No | No |
| Self-Documenting | Via OpenAPI | No | Via tools/list |
| Error Format | HTTP status codes | JSON-RPC errors | isError flag |
REST - The Classic Choice
REST is the most widely known API style. It uses HTTP methods to represent actions:- Your clients are web browsers or mobile apps
- You want caching (browsers cache GET requests)
- Your team is familiar with REST APIs
- You’re building a public API
JSON-RPC - The Power User’s Choice
JSON-RPC is a simple protocol where you explicitly name the method to call. All requests use POST.- Service-to-service communication
- You need to batch multiple operations
- Network latency is a concern
- Your operations don’t map cleanly to REST verbs
MCP - The AI-Native Choice
MCP (Model Context Protocol) is designed for AI assistants. It lets AI models discover and use your API as “tools”.- You want Claude or other AI assistants to use your API
- You’re building AI-powered applications
- You want automatic tool discovery
OpenAPI - The Documentation Choice
OpenAPI isn’t really a transport - it generates documentation from your service. Use it alongside other transports.- Swagger UI: Interactive API documentation
- Code generators: Generate client SDKs in any language
- API testing tools: Import into Postman, Insomnia, etc.
Using All Transports Together
Here’s how to serve your API via all protocols at once:http://localhost:8080/todos(REST)http://localhost:8080/rpc(JSON-RPC)http://localhost:8080/mcp(MCP)http://localhost:8080/openapi.json(OpenAPI spec)
How Errors Work Across Transports
One of Contract’s best features is consistent error handling. When you return an error:| Transport | Error Response |
|---|---|
| REST | HTTP 404 status, body: {"error": {"code": "NOT_FOUND", "message": "todo not found"}} |
| JSON-RPC | {"error": {"code": -32603, "message": "todo not found", "data": {"code": "NOT_FOUND"}}} |
| MCP | {"content": [{"type": "text", "text": "todo not found"}], "isError": true} |
Complete Example
Here’s a complete example with all transports. We organize the code with the todo service in its own package:Practical Recommendations
Starting a New Project
Start with REST + OpenAPI:Building a Web Application
REST is perfect for web applications:Building Microservices
JSON-RPC for service-to-service (batching is valuable):Building AI-Powered Apps
MCP for AI assistants, plus REST for human debugging:Building for Everything
Use all of them! There’s no conflict:Common Questions
Can I use multiple transports at once?
Yes! Each transport uses different paths, so they don’t conflict. This is actually recommended.Which transport is fastest?
They’re all similar in performance. The overhead is minimal compared to your actual business logic.Do I need to write different code for each transport?
No! That’s the whole point of Contract. Write your service once, expose it via any transport.Can I customize how a transport works?
Yes, each transport has options for customization. See the individual transport pages for details.How are method names formatted for each transport?
All transports use theresource.method pattern:
| Interface Method | Transport Method Name |
|---|---|
Create | todos.create |
List | todos.list |
Get | todos.get |
What’s Next?
Each transport has its own detailed documentation:- REST Transport - HTTP verbs, path patterns, customization
- JSON-RPC Transport - Batching, notifications, error codes
- MCP Transport - AI integration, Claude Desktop setup
- OpenAPI - Documentation, Swagger UI, code generation