Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do RESTful and SOAP Web Services differ in practice?

I am implementing web services for a PHP application and am trying to understand what both standard web services and RESTful web services have to offer. My intent is to write wrapper code to abstract away the web service details so that developers can just "instantiate remote objects" and use them. Here are my thoughts, perhaps some of you could add your experience and expand this:

RESTful Web Servcies

are basically just "XML feeds on demand", so e.g. you could write wrapper code for a client application so it could query the server application in this way:

$users = Users::getUsers("state = 'CO'");
  • this would in turn get an XML feed form a remote URL
  • $users could be made into a collection of full User objects, or
  • left as XML, or
  • turned into an array, etc.
  • the query script ("state = 'CO'") would be translated into SQL on the server side
  • RESTful Web Services are in general read-only from the view of the client, although you could write code which could use POST or GET to make changes on the server, e.g. passing an encrypted token for security, e.g.:

    $users = Users::addUser($encryptedTrustToken, 'jim',$encryptedPassword, 'James', 'Taylor');

and this would create a new user on the server application.

Standard Web Services

Standard Web Servcies in the end basically do the same thing. The one advantage they have is that client can discover their details via WSDL. But other than that, if I want to write wrapper code which allows a developer to instantiate, edit and save objects remotely, I still need to implement the wrapper code. SOAP doesn't do any of that for me, it can do this:

$soap = new nusoap_client('http://localhost/test/webservice_user.php?wsdl', true);
$user = $soap->getProxy(); 
$lastName = $user->lastName();

but if I want to edit and save:

$user->setLastName('Jones');
$user->save();

then I need to e.g. handle all of the state on the server side, SOAP doesn't seem to hold that object on the server side for each client.

Perhaps there are limitations in the PHP SOAP implementation I am using (nusoap). Perhaps Java and .NET implementations do much more.

Will enjoy hearing your feedback to clear up some of these clouds.

like image 269
Edward Tanguay Avatar asked Nov 17 '08 16:11

Edward Tanguay


People also ask

What is the difference between SOAP and RESTful services?

REST is a set of guidelines that offers flexible implementation, whereas SOAP is a protocol with specific requirements like XML messaging. REST APIs are lightweight, making them ideal for newer contexts like the Internet of Things (IoT), mobile application development, and serverless computing.

What is the difference between web service and RESTful web services?

1) Web API vs REST API: ProtocolWeb API supports protocol for HTTP/s protocol and URL requests/responses headers that enable services to reach various clients through the web. On the other hand, all communication in the REST API is supported only through HTTP protocol.

What is difference between REST API and REST web services?

Web Service uses a collection of open-source protocols to exchange data between applications whereas API acts as an interface between two applications to facilitate interaction with each other. The key difference is web service supports only HTTP while API supports HTTP/HTTPS protocol. A type of API is a web service.

What is the difference between SOAP and web services?

Web services overview Web services are of two kinds: Simple Object Access Protocol (SOAP) and Representational State Transfer (REST). SOAP defines a standard communication protocol (set of rules) specification for XML-based message exchange. SOAP uses different transport protocols, such as HTTP and SMTP.


2 Answers

They are different models... REST is data-centric, where-as SOAP is operation-centric. i.e. with SOAP you tend to have discrete operations "SubmitOrder", etc; but with REST you are typically a lot more fluid about how you are querying the data.

SOAP also tends to be associated with a lot more complexity (which is sometimes necessary) - REST is back to POX etc, and YAGNI.


In terms of .NET, tools like "wsdl.exe" will give you a full client-side proxy library to represent a SOAP service (or "svcutil.exe" for a WCF service):

var someResult = proxy.SubmitOrder(...);

For REST with .NET, I guess ADO.NET Data Services is the most obvious player. Here, the tooling (datasvcutil.exe) will give you a full client-side data-context with LINQ support. LINQ is .NET's relatively new way of forming complex queries. So something like (with strong/static type checking and intellisense):

var qry = from user in ctx.Users
          where user.State == 'CO'
          select user;

(this will be translated to/from the appropriate REST syntax for ADO.NET Data Services)

like image 75
Marc Gravell Avatar answered Nov 09 '22 05:11

Marc Gravell


I'm echoing what Marc Gravell mentioned. When people ask me about REST (and they usually have an idea about SOAP and SOA), I will tell them REST = ROA as it is resource/data oriented, it's a different paradigm and therefore has different design concerns.

For your case, if I'm reading you correctly, you want to avoid writing the wrapper code and need a solution that can store objects and their attributes remotely (and having them completely hidden from the developers). I can't really suggest a better solution.. Umm, let me know if either of these ever come close to meet your requirements:

  1. EJB3 / JPA
  2. CouchDB (REST/JSON)

Let me know too if I've interpreted your question wrongly.

If we compare XML-RPC and SOAP, the latter will give you better data types handling, for the former although you will be dealing with simpler data types but you will have to write a layer or adapter to convert them to your domain objects.

yc

like image 42
yclian Avatar answered Nov 09 '22 06:11

yclian