Web service differences between REST and RPC

后端 未结 9 1261
情歌与酒
情歌与酒 2020-12-07 06:54

I have a web service that accepts JSON parameters and have specific URLs for methods, e.g.:

http://IP:PORT/API/getAllData?p={JSON}

This is

相关标签:
9条回答
  • 2020-12-07 07:29

    Over HTTP they both end up being just HttpRequest objects and they both expect a HttpResponse object back. I think one can continue coding with that description and worry about something else.

    0 讨论(0)
  • 2020-12-07 07:33

    You can't make a clear separation between REST or RPC just by looking at what you posted.

    One constraint of REST is that it has to be stateless. If you have a session then you have state so you can't call your service RESTful.

    The fact that you have an action in your URL (i.e. getAllData) is an indication towards RPC. In REST you exchange representations and the operation you perform is dictated by the HTTP verbs. Also, in REST, Content negotiation isn't performed with a ?p={JSON} parameter.

    Don't know if your service is RPC, but it is not RESTful. You can learn about the difference online, here's an article to get you started: Debunking the Myths of RPC & REST. You know better what's inside your service so compare it's functions to what RPC is and draw your own conclusions.

    0 讨论(0)
  • 2020-12-07 07:38

    It is RPC using http. A correct implementation of REST should be different from RPC. To have a logic to process data, like a method/function, is RPC. getAllData() is an intelligent method. REST cannot have intelligence, it should be dump data that can be queried by an external intelligence.

    Most implementation I have seen these days are RPC but many mistakenly call it as REST. REST with HTTP is the saviour and SOAP with XML the villain. So your confusion is justified and you are right, it is not REST.

    Http protocol does not make an implementation of REST. Both REST(GET, POST, PUT, PATCH, DELETE) and RPC(GET + POST) can be developed through HTTP(eg:through a web API project in visual studio).

    Fine, but what is REST then? Richardson maturity model is given below(summarized). Only level 3 is RESTful.

    • Level 0: Http POST
    • Level 1: each resource/entity has a URI (but still only POST)
    • Level 2: Both POST and GET can be used
    • Level 3(RESTful): Uses HATEOAS (hyper media links) or in other words self exploratory links

    eg: level 3(HATEOAS):

    1. Link states this object can be updated this way, and added this way.

    2. Link states this object can only be read and this is how we do it.

      Clearly, sending data is not enough to become REST, but how to query the data, should be mentioned too. But then again, why the 4 steps? Why can't it be just Step 4 and call it REST? Richardson just gave us a step by step approach to get there, that is all.

    You've built web sites that can be used by humans. But can you also build web sites that are usable by machines? That's where the future lies, and RESTful Web Services shows you how to do it.

    • This book RESTful Web Services helps
    • A very interesting read RPC vs REST

    PS: REST is super popular so is automated testing but when it comes to real world examples .. well..

    0 讨论(0)
提交回复
热议问题