Web service differences between REST and RPC

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

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

This is definitely not REST as it is not stateless. It takes cookies into account and has its own session.

Is it RPC? What is the difference between RPC and REST?


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 (ie 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.


Consider the following example of HTTP APIs that model orders being placed in a restaurant.

  • The RPC API thinks in terms of "verbs", exposing the restaurant functionality as function calls that accept parameters, and invokes these functions via the HTTP verb that seems most appropriate - a 'get' for a query, and so on, but the name of the verb is purely incidental and has no real bearing on the actual functionality, since you're calling a different URL each time . Return codes are hand-coded, and part of the service contract.
  • The REST API , in contrast, models the various entities within the problem domain as resources, and uses HTTP verbs to represent transactions against these resources - POST to create, PUT to update, and GET to read. All of these verbs, invoked on the same URL , provide different functionality. Common HTTP return codes are used to convey status of the requests.
  • Placing an Order:

  • RPC: http://MyRestaurant:8080/Orders/PlaceOrder (POST: {Tacos object})
  • REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (POST: {Tacos object})
  • Retrieving an Order:

  • RPC: http://MyRestaurant:8080/Orders/GetOrder?OrderNumber=asdf (GET)
  • REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (GET)
  • Updating an Order:

  • RPC: http://MyRestaurant:8080/Orders/UpdateOrder (PUT: {Pineapple Tacos object})
  • REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (PUT: {Pineapple Tacos object})
  • Example taken from sites.google.com/site/wagingguerillasoftware/rest-series/what-is-restful-rest-vs-rpc


    REST is best described to work with the resources, where as RPC is more about the actions.

    REST stands for Representational State Transfer. It is a simple way to organize interactions between independent systems. RESTful applications commonly use HTTP requests to post data (create and/or update), read data (eg, make queries), and delete data. Thus, REST can use HTTP for all four CRUD (Create/Read/Update/Delete) operations.

    RPC is basically used to communicate across the different modules to serve user requests. eg In openstack like how nova, glance and neutron work together when booting a virtual machine.

    链接地址: http://www.djcxy.com/p/71470.html

    上一篇: SOAP为什么/如何是有状态的?

    下一篇: REST和RPC之间的Web服务差异