Skip to main content

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

Now call methods:

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 pattern resource.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:
Response:

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 the id field to send a notification. The server won’t send a response:
Use notifications for:
  • Logging or analytics events
  • Triggering background jobs
  • Sending metrics
You can batch notifications:

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 (with id) get responses, notifications (without id) don’t:
Response only includes the request:

What ID values can I use?

Any JSON value works:

How do I call methods without a resource?

If you didn’t use WithDefaultResource, use just the method name:
With a resource:

Can I generate an OpenRPC spec?

Yes:

What’s Next?