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:
*If you omit
id, it becomes a “notification” (no response sent).
Response Format
Success Response
Error Response
Method Naming
Method names follow the patternresource.method:
The resource name comes from
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:
Contract errors map to -32603 (Internal error) with the message from your error:
Multiple Services
Mount multiple services on the same endpoint:Combining with REST
Use JSON-RPC alongside REST:JSON-RPC vs REST
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