How JSON-RPC works

The JSON-RPC protocol uses JSON messages in the following format for a request:

{"jsonrpc": "2.0", "method": "substring", "params": [2, 6, "string"], "id": 1}

The preceding JSON message calls the substring remote method of a server that can return a result like this:

{"jsonrpc": "2.0", "result": "ring", "id": 1}

It's worth nothing that a client determines the identifier of the request and has to track those values. Servers are ID-agnostic and they use a connection to track requests.

There are two versions of the protocol—1.0 and 2.0. They are similar, but in the second version there is a separation of the client and the server. Also, it is transport independent, because the first version uses connection events to determine behavior. There are improvements for errors and parameters as well. You should use version 2.0 for new projects.

To support JSON-RPC, your server has to respond to these kind of JSON requests. The protocol is really simple to implement, but we will use the jsonrpc-http-server crate, which uses HTTP transport and provides types to bootstrap a server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.77.63