REST vs RPC - *Actual purpose* differences -
i started writing web-apps , distributed apps when rest popular, never used rpc.
when searching simple explanation of difference between them, started understand, examples got me confused.
saw things this:
get /getlastuser
or this:
post /changeusername
if rest meant resources, , rpc meant procedures, isn't bad practice using rpc this?
correct me if i'm wrong, way see it, rpc should more purely functional.
meaning calling procedure should always:
- return same result same arguments
- not affect state
so, rpc calls this:
get /addtwo?num=5
that return this:
{ "result": 7 }
seem more logical me (although that's simple example).
if question gets closed being "opinion-based", i'll know should whatever heck want...
rpc not meant functional. calling same procedure twice gives no guarantee result.
this question can answered few different ways, , pretty deep. think might fair summary.
- with rpc primitives typically function names, arguments , results.
- with rest primitive 'resource representation'.
so rpc might call function, in rpc sending , retrieving state of resource, regardless of protocol.
this means typically ask server 'can give me state of resource', or tell server 'here's new resource state, please store @ location'. successful answers rest give "the current state" or "this operation worked", rpc question (function + arguments) , answer (the result) can anything.
so can argue when describe this, rpc lot more flexible. is, because rest confines transmitting state, gain lot of guarantees simple rpc-based protocol not give.
rest not transferring state. usage hyper-links important requirement service called rest, , don't 'out of box' rpc.
lastly, can argued http rpc-like protocol. think it's possible build restful service on top of rpc service.
Comments
Post a Comment