JSON-RPC for react project

Viewed 823

In a React app, I need to work with JSON-RPC API. I found some libraries that act as a JSON-RPC client. But it's not entirely clear to me whether I should install with a special client. I tried sending a request using axios and it looks like everything is working. Or am I missing something?

Therefore, I will be grateful if you answer at least one of my questions:

  • Сan use the fetch or axios to send and receive data in json-rtc format?

    axios.post(`/link-to-rpc-api`, {
      "jsonrpc": '2.0',
      "method": 'transformMessage',
      "id": 1,
      "params": {
        "message": 'Test',
      }
    });
    
  • If so, how can I execute batch requests?

  • Are there any best practices/libraries for json-rpc to work in a React app?

Thanks a lot!

1 Answers

If you want to use Axios of fetch which you can, you should read the specification of the JSON-RPC 2.- protocol. Libraries did that and you have clients. The specification has everything you need to know (also how to send batches). It's not difficult to read and it's short.

Related