> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/api-sec/rpc-and-grpc-vs-rest.md).

# RPC & gRPC vs REST

### **Remote Procedure Call (RPC)**

Remote Procedure Call (RPC) is a communication protocol that enables a program to request a service or execute a function located on another computer (or remote server) as if it were a local procedure.

* The client calls a function or method, and the underlying system handles the communication with the server.
* The server executes the requested function and returns the result to the client.
* RPC abstracts the complexities of the network, making remote calls appear similar to local calls.
* Popular implementations include **gRPC** (Google Remote Procedure Call), which uses HTTP/2 and Protocol Buffers for efficiency.

**Key characteristics:**

* Procedure/method-oriented.
* Tight coupling between client and server interfaces.
* Often faster and more efficient for inter-service communication.

#### Procedure

A **procedure** is basically a **named block of code** that does a specific job.

* You might also hear it called a **function**, **method**, or **subroutine** (the terms can vary depending on language).
* A procedure usually:
  1. Has a **name** (so you can call it).
  2. May take **inputs** (called *parameters* or *arguments*).
  3. Performs some **steps or logic**.
  4. May give back an **output** (a *return value*).

Example:

```python
def add(a, b):
    return a + b
```

Here, `add` is a **procedure** that:

* Takes inputs `a` and `b`.
* Performs the action "add them together".
* Returns the result.

{% hint style="success" %}
So when we say **Remote Procedure Call (RPC)**, it just means: 👉 *“Run that procedure (like `add`) on another computer, not just locally.”*
{% endhint %}

***

### **Representational State Transfer (REST API)**

REST (Representational State Transfer) is an architectural style for building APIs that rely on standard web protocols, typically HTTP. In a REST API, resources (such as users, files, or orders) are represented with unique URLs, and standard HTTP methods are used to interact with them.

* **GET** retrieves data.
* **POST** creates new resources.
* **PUT/PATCH** updates existing resources.
* **DELETE** removes resources.

**Key characteristics:**

* Resource-oriented (focuses on resources and their representations).
* Loose coupling between client and server.
* Stateless: each request contains all the necessary information, with no dependency on previous requests.
* Widely used for web services due to simplicity and scalability.

***

**In short:**

* **RPC**: Call remote functions directly as if they were local.
* **REST API**: Interact with resources over HTTP using standard methods.

***

### Reference

* <https://aws.amazon.com/compare/the-difference-between-rpc-and-rest/>
* <https://rootxjs.github.io/docs/grpc_goat_docs/grpc-basics/>
