Sobes.tech
Middle

What are the main differences between REST and RPC architectural styles?

sobes.tech AI

Answer from AI

REST is based on resources and their states, using standard HTTP methods (GET, POST, PUT, DELETE) to operate on them. RPC is oriented towards calling remote procedures or functions.

Characteristic REST RPC
Focus Resources Actions (functions/procedures)
Protocol HTTP Flexible (HTTP, TCP, AMQP, etc.)
Interaction Manipulating resources via HTTP methods Calling remote functions
Standardization High (HTTP, URI, media types) Depends on technology/protocol
State Stateless Can be stateful or stateless
Caching Supported by HTTP mechanisms Depends on implementation
Example call GET /users/123 getUser(id=123)

In REST, the client sends a request to a URI representing a resource, using an HTTP method to specify the desired operation. The server processes the request and returns a representation of the resource.

// Logical REST request
// GET /api/users/123
// HOST: example.com

In RPC, the client calls a function on the remote server, passing parameters. The server executes the function and returns the result.

// Logical RPC call
// client.call("getUser", {"id": 123})

REST is better suited for data operations (CRUD) and when scalability, caching, and standard interaction are important. RPC is often chosen for executing specific, complex operations or when a binary protocol is needed for performance.