Our Blogs

JSON-RPC Gets Better With Enhanced Features And Notifications

December 17, 2017
We all know that Language Server Protocol aka LSP is designed and developed on top of JSON-RPC 2.0. The framework was developed 10 years ago and it was not popular as SOAP or REST. The JSON-RPC is based on JSON and is mainly used to perform remote procedure calls. If you look at REST, it is data-centric. With REST, you will be able to create, modify and fetch documents and records automatically.

In RPC, you need to call functions that would normally exist in an external program. However, the functions are liable to manipulate documents. The REST will be able to work more than simply storing data.  The JSON-RPC 2.0 is more or less a lightweight alternative to SOAP. It is to be noted that other related parameters such as sockets, stdio, named pipes, HTTP are outside the preview of the protocol.

As a developer, you can make use of the JSON-RPC to work with asynchronous transports such as message queues. You need to include a correlation ID with each request. The purpose of the mechanism is to enable efficient communication instead of traditional HTTP. It permits multiple requests to work at the same time without any need for any multiple connectivities.

The advantage of JSON-RPC is that it provides support for batch operations. For example, a single message will have an unlimited number of requests in an array. You should note that the responses will occur in any order and hence the importance of correlation ID is relevant. Moreover, the framework also provides support for notification, which doesn't require a correlation ID.

If you make use of the notifications, the server cannot respond to the message and hence the use of the same is highly discouraged. In JSON-RPC, errors are reported only via a code and message. You will experience error codes in the -32768 to -32000 range. They are used for throwing exceptions such as invalid parameter and method not found.