Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SOAP and REST

I have used SOAP service successfully.

Suppose there is a Web Service that exposes a method that returns the list of Students.

public Student[] listAllStudents(){
  //some code that return Student array
}

Using SOAP will need these steps:

  1. Get the URL for the location of WSDL.
    eg. http://127.0.0.1/web/service/location/soap.php?wsdl
  2. Use some available technologies like axistools-maven-plugin to generate all stub classes. There will be a generated class with the name like Student
  3. Use the appropriate stub class/interface to invoke the service.

    Student[] students = theStub.list_All_Students();

Using REST service will be something like this.

  1. Get the right url for getting list of Students.
    eg. http://127.0.0.1/web/service/student/list?sort=true
  2. Use some URL Connection techniques like java.net.HttpURLConnection to get the result which is usually in JSON format.
  3. Parse the result.

As a Java programmer, I have no problem in using SOAP because there are frameworks designed for it. Moreover, there is only one URL that I need to know for hitting the Web Service.

Using REST is a bit confusing. I need to know all the specific URLs along with the query string required to be passed. From this point of view using REST is quite cumbersome.

My Questions:

  1. From the programmer's perspective, is using REST useful at all?
  2. Is there any good framework that will make hitting REST easier?
like image 687
Mawia Avatar asked Apr 04 '13 07:04

Mawia


People also ask

Can I use REST with SOAP?

SOAP cannot make use of REST since SOAP is a protocol and REST is an architectural pattern.

When should we use SOAP and when REST?

A general rule of thumb when you're deciding between SOAP and REST for building your API: if you want standardization and enhanced security, use SOAP. If you want flexibility and efficiency, use REST. For specific use cases of when to use SOAP vs REST, check out the table below.

Can you use SOAP in REST API?

A REST API can actually utilize the SOAP protocol, just like it can use HTTP.

What is difference between SOAP and REST with example?

SOAP uses only XML for exchanging information in its message format whereas REST is not restricted to XML and its the choice of implementer which Media-Type to use like XML, JSON, Plain-text. Moreover, REST can use SOAP protocol but SOAP cannot use REST.


2 Answers

1. From the programmer's perspective, is using REST useful at all?

REST is definitely useful. It's a different way of utilizing web services, compared to what you're used to in SOAP. Here's a quick comparison: enter image description here

In the end, they each serve their own purpose in the service-oriented world. SOAP is mature but bloated. REST is relatively younger, but is a more natural fit with HTTP. It has huge potential, especially when service contract standards are put into place. When WADL matures, it will boost the popularity and adoption of REST.

2. Is there any good framework that will make hitting REST easier?

A lot. Here are some of the known REST frameworks, with the popular ones being JAX-RS, Jersey, RESTEasy and Restlet.

like image 60
Jops Avatar answered Oct 26 '22 01:10

Jops


This is quite an open ended question, but REST is much more interoperable, not to mention the sheer amount of metadata in each query makes it hardly light weight. Consider if you had to query a SOAP endpoint in javascript, or even php can be a pain in the ass. SOAP uses a contract first mechanism that's really suited when you want to consume it using something like c#.

On your second question, yes, you can parse the RESTful response with either Jackson (only for JSON), RestController in Spring, or JAX-RS.

like image 23
david99world Avatar answered Oct 26 '22 00:10

david99world