Develoraptor Blog

Login

JSON-RPC, the transparent API protocol

Posted by

When web developers want to create an HTTP API, they generally reach for REST because it's familiar and ubiquitous. And while it's a great protocol for reading and writing files and documents, I don't think it's always the best choice for every web app.

I've had many headaches trying to figure out how to make a particular operation fit in the REST paradigm. How should you represent a "restart", "initiatePasswordReset", or "makeCupOfCoffee" function call in REST? It's possible, but it's not obvious.

This is where JSON-RPC excels. Because a JSON-RPC request is comprised of a method name and parameters, there is a one-to-one mapping between a request and the function that it calls. Your client library can use the exact same interface as you would use if you were calling these functions on the server.

RPC sometimes gets overlooked because because of its old association with XML and sprawling collections of methods - but it doesn't have to be this way with a modern interchange format and the same care and restraint you would give to any interface.

As I said, I don't think REST is bad: I plan to use it for all of my file-based endpoints. But I think JSON-RPC is much simpler when all I want to do is call a few functions.