In the previous tutorial, we discussed the features of SoapUI Pro and briefly touched about SOAP vs REST web services. This tutorial will give you SOAP (Simple Object Access Protocol) and REST (Representation State Transfer) based services and their advantages in detail.
=> Click here for the complete list of SoapUI and SoapUI Pro tutorials in this series.
Understanding REST and SOAP Services:
A web service is a program that helps us to connect two computers over the World Wide Web. Web services are the software component that supports machine to machine interaction over network. This is called interoperability which can be achieved by machine understandable format document called WSDL. WSDL is processed by SOAP and it transfers via HTTP in the form of XML.
Look at this pictorial representation of the web service flow.
What You Will Learn:
What is SOAP Service?
It is basically a protocol which has a set of defined rules to transfer the structured information implemented through web services. SOAP uses XML format data which is platform independent so it can support all the major protocols such as HTTP, FTP, TCP, and UDP and so on.
SOAP services follow the standards for sending and receiving message with the unique format. Usually SOAP message contains the following information:
- Request / Response Data
- action to be performed
- Header information
- Error details if any failure messages
In SOAP, security related services given by WS-Security standards are in both the client and server side. WS-Security offers data integrity and privacy. WS-ReliableMessaging is another feature that provides end to end reliable services for success and failure cases.
WSDL is the major technique for handling SOAP service information.
What is REST (Representational State Transfer)?
It is architecture based specially designed for networking applications and is used in client-server systems to send request and response. REST services are also called as RESTful APIs as it is implemented by using Hypertext Transfer Protocol (HTTP). It is GUI independent, and we can test REST APIs using SoapUI without the actual application. It follows a stateless method which means, whenever the client sends the request to the server, server does not store any data in the session.
SOAP vs. REST
- SOAP is a protocol and REST is architecture. It allows us to send SOAP envelops to REST based applications.
- REST supports different message formats but SOAP permits XML only.
- REST services are faster and easy to handle.
- SOAP is tied with SMTP and HTTP protocols whereas REST relies on HTTP only.
- SOAP is more secure and structured format.
- REST does not depend on any specific standards as it supports various messaging formats like JSON, CSV and XML.
- SOAP web services allow us to build the client with RESTful services.
- SOAP was introduced for distributed computing.
- After REST’s entry, it accommodated the web by its performance and scalability as it is a light weight component.
- REST is stateless whereas SOAP is a state-ful specification.
- REST uses Uniform Resource Identifier (URI) and it has the methods like GET, PUT, POST and DELETE to expose their resources.
- SOAP uses named operations and interfaces to achieve its business logics.
Now let us discuss REST services by creating REST project in SoapUI Pro.
Creating REST Project in SoapUI Pro:
Follow the below steps:
1) Open SoapUI Pro application and right click on the Projects node present in the Navigator panel
2) In the context menu, click New REST Project option
3) Enter the following Google Map API location in the given text field: http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
4) On OK, SoapUI Pro will create project tree along with resources, service, methods, and endpoint with input request in the editor. See below:
(Click image for enlarged view)
5) As you can see in the above screenshot, there is a parameters section. If you click on it, it will show you the parameters that are used in the service in a separate popup window.
(Click image for enlarged view)
We are done with functional testing for Google Map API. Let’s add test suites and test cases to get to know more about REST services.
To add test case, do the following:
2) Enter the test suite name and then click OK
3) Then provide the test case name and click OK button
4) In the Add Request to Testcase dialog, enter the request name and then click OK button
5) Now the test suite tree will look like this.
6) Run the test suite by double click on the test suite name
7) Here is the test suite results
10) In the Create Report window, make sure the format is selected TestSuite Report
11) Or else you can use JUnit-Style HTML Report format
12) Click OK button and verify the results
Similarly, we can add REST services, resources and methods. As we discussed we can have any number of resources in the resource path.
Let us start with adding REST service:
- Right click interface name which shows as http://maps. Googleapis.com
- Then click New Resource option from the context menu
- It opens the New REST Resource In that enter the resource path as http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
- Click OK
- Now the request is added under the project tree. If we wish, we can rename it to be meaningful
- In the Form tab, change the address as 2176 Heron Way, Portland, OR
- Click on the icon to view the results. Refer the following screenshot.
Difference Between SOAP and REST services:
Now you know how to add REST resources. Here I have summarized the differences between SOAP and REST services.
|SOAP is abbreviated as Simple Object Access Protocol||REST stands for Representational State Transfer|
|It is basically XML based message transfer protocol||REST is standard architecture to build web services.|
|Request and Response data are used in the form of XML||REST service request and response data can be JSON, CSV and XML|
|It is complicated whenever the WSDL file is changed because we need to re-generate WSDL to build the client accordingly.||We can use REST APIs without disturbing the existing client.|
|SOAP is tied with HTTP and SMTP protocols||REST relies on only HTTP|
|Do not have built-in error handler||Supports error handler for identifying the faults during run-time|
|SOAP messages cannot be cached when it reads||REST data can be cached|
So far in this tutorial, we learned SOAP and REST services and their advantages and differences.
We can also add assertions for the REST services to assert our services. We can add any number of REST test steps and transfer the data between each with the property transfer.
In the next SoapUI Pro tutorial, we will see Data Driven Testing. Please let us know your comments and questions below.