# Comparison of API Patterns
###### tags: `Server` `System Design` `Distributed System` `Protocol` `Software` `API` `Cross Platform` `App`
SOAP vs. RESTful vs. GraphQL vs. RPC vs. gRPC

## Comparison of Connection Rules
> Clients <- APIs rules -> Servers

### RESTful API
methods of *Create-get, Read-post, Update-put, Delete-patch*
```nginx
GET example.com/api/v2/users
```
### RPC (Remote Procedure Calls)
methods of *ReadOnly-get & OtherActions-post*, take advantage of flexibility, verb-like methods, it's better used in microservices communications than clients.
```nginx
POST example.com/api/chat.postMsg
```

#### pros (vs. REST)
* Protocol Buffer vs. xml, json
| | protobuf | json |
|:-----------:|:------------:|:--------:|
| payload | encoding bin | raw data |
| performance | 5x faster | 1x |
* HTTP/2 - serial request in a single connection
#### cons
* en / decode overhead
* web client on browsers not supported (due to HTTP/2)
### GraphQL
can freely fetch desired data fields in a single call, but difficult for server to handle, for client to do advanced operation
```nginx
GET https://api.line.me/v2/list
{Users{userId,name}}
```
## todo: Benchmarks
1. gRPC vs. REST
2. vm cluster (servs / nas / san) vs. container vs. application
---
## ref
[What is RPC? gRPC Introduction. - ByteByteGo](https://www.youtube.com/watch?v=gnchfOojMk4&ab_channel=ByteByteGo)
[8 Key Data Structures That Power Modern Databases - ByteByteGo](https://www.youtube.com/watch?v=W_v05d_2RTo&ab_channel=ByteByteGo)
[gRPC Crash Course - Modes, Examples, Pros & Cons and more - Hussein Nasser](https://www.youtube.com/watch?v=Yw4rkaTc0f8&ab_channel=HusseinNasser)
[nginx - github](https://github.com/nginx/agent)