Sobes.tech
Senior

What types of web APIs do you know? How does REST differ from RPC in essence?

sobes.tech AI

Answer from AI

Web APIs come in different types, the main ones are:

  • REST (Representational State Transfer) — an architectural style that uses HTTP methods (GET, POST, PUT, DELETE) to work with resources identified by URIs. REST is resource-oriented and focuses on resource states.
  • RPC (Remote Procedure Call) — calling remote procedures or functions, where the client invokes server methods as if they were local. Usually, method names and parameters are passed.
  • GraphQL — a query language that allows the client to request exactly the data it needs.

Differences between REST and RPC:

  • REST works with resources and their states, not with function calls.
  • REST operations are standardized with HTTP methods, while RPC calls specific methods by name.
  • REST is more oriented towards data structure and presentation, RPC towards actions.

Example:

REST request to get a user:

GET /users/123

RPC request to get a user:

POST /rpc
{
  "method": "GetUser",
  "params": { "id": 123 }
}

Thus, REST is more declarative and resource-oriented, while RPC is focused on procedure calls.

What types of web APIs do you know? How does REST… - sobes.tech