Question

I don't understand what the ID is for in JSON RPC. Also, how bad is it considered to not use JSON-RPC.org's standards when developing a toolkit? There seems to be some ambiguity in the JSON-RPC world.

P.S. The ID I'm referring to is the id in here:

{"params":["Hello","World"],"method":"hello_world","id":1}
Was it helpful?

Solution

You're not guaranteed to get your answers back in the order you asked for them; the id is to help you sort that out.

OTHER TIPS

The "id" is returned in the corresponding response object, so you can map one context to the other.

If you are making synchronous single calls, it might not make sense, but in an async multi-outstanding-call enviroment it is vital.

It should not be hard coded to 1, but set to a unique value for every request object you generate from the client.

None of the answers mentions the difference between the two existing versions of the protocol.

JSON RPC 1.0:

The request id. This can be of any type. It is used to match the response with the request that it is replying to.

JSON RPC 2.0:

An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts.

Thus it is perfectly fine in JSON RPC 2.0 to set id to some fixed value. But be aware of the use of id in batch requests.

  1. To let the server know you're expecting a response.
  2. To match responses to requests when using asynchronous or batch calls.

You can read the JSON RPC docment https://www.jsonrpc.org/specification. In the "4 Request object" the id param is explain clearly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top