Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON RPC - What is the "id" for?

Tags:

json

json-rpc

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} 
like image 950
orokusaki Avatar asked Feb 05 '10 22:02

orokusaki


People also ask

What is JSON-RPC used for?

JSON-RPC is simply a remote procedure call protocol that is used on Ethereum to define different data structures. It also defines the rules on how data structures are processed in the network. Because it is transport-agnostic, you can use it to interact with an ETH node over sockets or HTTP.

What is JSON-RPC format?

JSON-RPC is a remote procedure call protocol encoded in JSON. It is similar to the XML-RPC protocol, defining only a few data types and commands.

What is a JSON-RPC endpoint?

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments.

Should I use JSON-RPC?

It would be better to choose JSON-RPC between REST and JSON-RPC to develop an API for a web application that is easier to understand. JSON-RPC is preferred because its mapping to method calls and communications can be easily understood.


2 Answers

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.

like image 33
MPCM Avatar answered Sep 23 '22 20:09

MPCM


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.

like image 103
Andrew McGregor Avatar answered Sep 24 '22 20:09

Andrew McGregor