Many situations developers have a debate on REST vs JSON-RPC. Plenty of resources available in Internet to distinguish them. This is one among them and direct how to create and use JSON-RPC with Delphi MVC Framework quickly.
REST: The Word REST is the Abbreviation of the Phase ‘Representational State Transfer’ is the Architectural Design Style and it is not a standard or Protocol. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the internet. REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems.
RPC: A remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.
JSON-RPC : JSON-RPC is a stateless, Light-weight remote procedure call(RPC) protocol.
- It is transport agnostic, and can be used within the same process, over sockets, over http, or in many various message passing environments.
- It uses JSON(RFC 4627) as data format.
- It supports Requests( which are functions) and Notifications( which are procedures)
Request and response:
[crayon-673fe22592c06195107148/]Notification (no response):
[crayon-673fe22592c21204148534/]Why JSON-RPC if i have REST?
RPC and REST are only different approaches with pros and cons and both are valuable depending on the context. The context is the key.
There are no universal solutions, you always have to think within a context and must be pragmatic when choosing a solution.
REST Vs JSON-RPC :
REST is Resource oriented while RPC is actions oriented.
REST is strongly tied with the transport protocol while RPC don’t.
REST-based APIs are great for CRUD based operations(Resources and entities). REST is not only CRUD, but things are done through mainly CRUD-based operations.
RPC can works with Sockets, http/https ftp, file system etc. Really it is not tied with any protocol, its just a way to describe an action with its parameters.
RPC-based APIs are great for actions based operations(functions and procedures)
Check this Video which demonstrates JSON-RPC with Delphi MVC Framework.
Check the sample made for JSON-RPC here.