Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web service differences between REST and RPC

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 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?

like image 870
Mazmart Avatar asked Sep 29 '22 13:09

Mazmart


People also ask

What is the difference between RPC and HTTP?

RPC is action-oriented. In contrast, REST is resource-oriented. REST utilizes HTTP methods GET, POST, PUT, PATCH, and DELETE to perform CRUD operations. However, RPC only supports GET and POST requests.

Is REST more suitable than RPC?

REST is made out by many to be ultimately superior to the other “RPC-based” approaches, which is a bit misleading because they are just different. This article discusses these two approaches in the context of building HTTP APIs, because that is how they are most commonly used.

What is difference between REST and Web services?

Web services are a type of API, which must be accessed through a network connection. REST APIs are a standardized architecture for building web APIs using HTTP methods.


1 Answers

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

like image 259
GorvGoyl Avatar answered Oct 13 '22 11:10

GorvGoyl