Skip to main content
When you build an API with Contract, you write your business logic once. But different clients need to talk to your API in different ways. That’s what transports are for - they let the same code speak multiple languages.

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:

Decision Guide: Which Transport Should I Use?

Use this flowchart to pick the right transport for your use case:
Pro tip: You can (and should!) use multiple transports at once. They don’t conflict.

Detailed Comparison

Feature Comparison

REST - The Classic Choice

REST is the most widely known API style. It uses HTTP methods to represent actions:
When to use REST:
  • 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
Pros: Familiar, cacheable, works everywhere Cons: No batching, multiple round trips for complex operations

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.
The killer feature is batching - send multiple operations in one request:
When to use JSON-RPC:
  • Service-to-service communication
  • You need to batch multiple operations
  • Network latency is a concern
  • Your operations don’t map cleanly to REST verbs
Pros: Batching, explicit method names, standard protocol Cons: POST only, less familiar to web developers

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”.
When to use MCP:
  • You want Claude or other AI assistants to use your API
  • You’re building AI-powered applications
  • You want automatic tool discovery
Pros: AI assistants understand it natively, self-documenting Cons: Specialized use case, more complex protocol

OpenAPI - The Documentation Choice

OpenAPI isn’t really a transport - it generates documentation from your service. Use it alongside other transports.
The spec can be used with:
  • 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:
Now the same service is accessible via:
  • 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:
Each transport formats it appropriately: You don’t need to handle each protocol separately.

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:
Add more transports as needed.

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 the resource.method pattern: For REST, method names are mapped to HTTP verbs and paths automatically.

What’s Next?

Each transport has its own detailed documentation: