Senior
Ποιοι τύποι web-API γνωρίζετε; Πώς διαφέρει ουσιαστικά το REST από το RPC;
sobes.tech AI
Απάντηση από 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 focuses on resources and their 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 transmitted.
- 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.
- In REST, operations are standardized by HTTP methods, in RPC, specific methods with names are called.
- 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 focuses on procedure calls.