jsonrpc2 icon indicating copy to clipboard operation
jsonrpc2 copied to clipboard

Add support for compliant batch requests

Open Lukasz032 opened this issue 2 months ago • 1 comments

JSON-RPC 2.0 specification defines something called batch requests, a way to send multiple requests inside one payload.

Technically, it's just a JSON array of valid requests, and those should just be processed in order, with responses also formatted as a JSON array.

Currently, the implementation doesn't support those, trying to send batch requests result in the following error:

unmarshaling jsonrpc message: json: cannot unmarshal "[{\"jsonrpc\":\"2.0\",\"id\":175924882..." into Go value of type jsonrpc2.combined

Compliant implementation could be attached to the stream logic (including rawStreams), so should a stream's Read() method encounter a JSON array instead of a single request, it would read that array to an intermediary []json.RawMessage cache, get the first entry, process it, then get the next, process it, and repeat until there are no requests left. Then the responses would be put into an array, serialized and returned.

Lukasz032 avatar Sep 30 '25 18:09 Lukasz032