Web service differences between REST and RPC

后端 未结 9 1302
情歌与酒
情歌与酒 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:18

    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

提交回复
热议问题