What is JSON-RPC?
JSON-RPC (Remote Procedure Call) is a protocol where you explicitly name the method you want to call. Unlike REST which uses different HTTP verbs and paths, JSON-RPC sends all requests to a single endpoint with the method name in the request body. Its killer feature? Batching - send multiple requests in one HTTP call.Quick Start
Request Format
Every JSON-RPC request has the same structure:| Field | Required | Description |
|---|---|---|
jsonrpc | Yes | Always "2.0" |
id | No* | Identifies your request (returned in response) |
method | Yes | resource.method name to call |
params | No | Object with method parameters |
id, it becomes a “notification” (no response sent).
Response Format
Success Response
Error Response
Method Naming
Method names follow the patternresource.method:
| Interface Method | JSON-RPC Method |
|---|---|
Create | todos.create |
List | todos.list |
Get | todos.get |
Delete | todos.delete |
Update | todos.update |
WithDefaultResource or WithResource.
Batching
Batching lets you send multiple requests in one HTTP call. Instead of N HTTP round trips, you make just 1.How to Batch
Send an array of requests:When to Use Batching
- Dashboard loads: Fetch user, settings, and recent items in one call
- Bulk operations: Create 100 items without 100 HTTP requests
- Related data: Get a todo and its comments together
- Service-to-service: Microservices calling each other
Notifications (Fire and Forget)
Omit theid field to send a notification. The server won’t send a response:
- Logging or analytics events
- Triggering background jobs
- Sending metrics
Complete Example
This example shows a JSON-RPC service using the recommended package-based organization:Test It
Error Codes
JSON-RPC uses standard error codes:| Code | Message | What It Means |
|---|---|---|
| -32700 | Parse error | Invalid JSON |
| -32600 | Invalid Request | Missing jsonrpc or method |
| -32601 | Method not found | Method doesn’t exist |
| -32602 | Invalid params | Wrong parameter types |
| -32603 | Internal error | Your method returned an error |
Multiple Services
Mount multiple services on the same endpoint:Combining with REST
Use JSON-RPC alongside REST:JSON-RPC vs REST
| Use JSON-RPC when… | Use REST when… |
|---|---|
| You need batching | Browser is the main client |
| Service-to-service calls | You want HTTP caching |
| Methods don’t map to CRUD | Team knows REST |
| You want explicit method names | Building a public API |
Common Questions
Can I mix requests and notifications in a batch?
Yes! Requests (withid) get responses, notifications (without id) don’t:
What ID values can I use?
Any JSON value works:How do I call methods without a resource?
If you didn’t useWithDefaultResource, use just the method name:
Can I generate an OpenRPC spec?
Yes:What’s Next?
- REST Transport - For browser-friendly APIs
- MCP Transport - Connect to AI assistants
- Error Handling - Error codes and handling
- Transports Overview - Compare all transports