by bigmanwalter · 9y ago · 0 comments
REST:
GET /api/item/1
GET /api/item/2
POST /api/item { name: foo, collection: 1 }
POST /api/item { name: bar, collection: 1 }
RPC: GET /api/items
POST /api/items [{ name: foo, collection: 1 }, { name: bar, collection: 1 }]REST:
GET /api/items (returns a list of items)
GET /api/items/1 (returns item with id#1)
POST /api/items (creates a new item, "adds" it to the list)
PUT /api/items/1 (updates item with id#1, the whole resource needs to be sent)
PATCH /api/items/1 (updates item with id#1, only changes in the resource need to be sent)
DELETE /api/items/1 (updates item with id#1, only changes in the resource need to be sent)
RPC (one possible implementation): GET /api/listItems (lists all items)
POST /api/addItem (adds an item)
POST /api/updateItem (updates an item, the id is in the payload)
GET /api/deleteItem (deletes the item)
(Verbs don't matter in RPC, I only used POST in favour of GET in the above examples because some clients and servers enforce limits on the size of GET requests.) PATCH /api/items/greaterthan/4 { active: false }
Whereas with RPC you can easily do: POST /api/items?greaterthan=4 { active: false }
In REST, you would do POST /api/item_updates/ { greatherthan: 4, active: false }
It comes off as messy to me as I would prefer to keep all endpoints around manipulating a particular model within the same controller rather than having multiple controllers for each model.I find there's an impedance mismatch between what endpoints my solutions need and what REST dictates. And it requires a lot of acrobatics to map my solution onto the REST way.
Can you point me to documentation that supports this claim? I've yet to see anything that expressly prohibits batched requests.
RPC would involve client lib. And may or may not even use HTTP as transport.
api.get_product(id=1)
api.add_product(details)
Maybe a clearer example around running a script:
REST:
POST /api/action { action: do_the_thing }
RPC: POST /api/do_the_thing
RPC is the most basic mapping of actions > endpoints whereas REST demands you organize everything into resources.I think that it also stems from most ORM's focus on updating single database rows at a time even though operations frequently span across multiple rows.
As all data manipulation ultimately happens on the server, I feel it's often unnecessary to keep track of individual resources in the client.