RPC
Before REST became popular, most APIs were built using XML-RPC or SOAP, which are two RPC-based HTTP APIs. So what exactly is RPC?
RPC (Remote Procedure Call) is just a way to call a function on a remote server. An RPC request represents an action and is structured like a function call in a programming language: there's a function name, function arguments, and possibly a return type. The server sees this call, does some internal processing, and then if a result is expected, it's going to send the resulting object back.
In contrast to REST, RPC isn't strict in HTTP verb usage: it only uses GET
to fetch data and POST
for everything else.
RPC introduces tight coupling between the client and the server: in addition to knowing about server resources, the client needs to know about the functions that can be called, the arguments that these functions need, and how to deal with the data coming back from these calls.
If the RPC server's API documentation is published, then it makes it clear to see what actions are available on the server. However, when client developers don't have access to either the underlying server code or API documentation, understanding proper RPC API usage can get really hard.
RPC is a good fit for APIs that are based on actions to take or processes to execute. It's also considered to be a better choice for non-public APIs or server-to-server interaction.
Here are examples of RPC calls:
1GET /readListOfEmployees?employeeId=25
1POST /modifyEmployee
2{
3"employeeId": "25",
4"position": "Regional Director"
5}
1POST /remoteDepartment
2{
3"departmentId": "3"
4}