We all must have heard about SOAP services and REST services, which is very common in now a days. Around the globe all the complex projects at some places used SOAP and/or REST services. In this tutorial we will talk about basics of SOAP and REST and later we will explain how to test these services. Before we start let’s understand what is web service?
“…A web service is a method of communication between two electronic devices over World Wide Web. It is a software function provided at a network address over the web with the service always on as in the concept of utility computing.”
In simple words – Web service is a mechanism that provides data as a service/response over the http protocol on request of some other programs.
SOAP (Simple Object Access Protocol):
SOAP is a method of transferring messages, or small amounts of information, over the Internet.
SOAP messages are formatted in XML and are typically sent using HTTP (hypertext transfer protocol).
- WSDL defines contract between client and service and is static by its nature.
- SOAP builds an XML based protocol on top of HTTP or sometimes TCP/IP.
- SOAP describes functions, and types of data.
- SOAP is a successor of XML-RPC and is very similar, but describes a standard way to communicate.
- Several programming languages have native support for SOAP, you typically feed it a web service URL and you can call its web service functions without the need of specific code.
- Binary data that is sent must be encoded first into a format such as base64 encoded.
- Has several protocols and technologies relating to it: WSDL, XSDs, SOAP, WS-Addressing.
Sample WebService URL and Response: http://www.webservicex.com/globalweather.asmx?wsdl
REST (REpresentational State Transfer):
Rest is a simple way of sending and receiving data between client and server and it doesn’t have very many standards defined. You can send and receive data as JSON, XML or even plain text. It’s lightweight compared to SOAP.
- In case of REST contract between client and service is somewhat complicated and is defined by HTTP, URI, Media Formats and Application Specific Coordination Protocol. It’s highly dynamic unlike WSDL.
- REST is very lightweight, it says wait a minute, we don’t need all of this complexity that SOAP created.
- Typically uses normal HTTP methods instead of a big XML format describing everything. For example to obtain a resource you use HTTP GET, to put a resource on the server you use HTTP PUT. To delete a resource on the server you use HTTP DELETE.
- REST is a very simple in that it uses HTTP GET, POST and PUT methods to update resources on the server.
- REST typically is best used with Resource Oriented Architecture (ROA). In this mode of thinking everything is a resource, and you would operate on these resources.
- As long as your programming language has an HTTP library, and most do, you can consume a REST HTTP protocol very easily.
- Binary data or binary resources can simply be delivered upon their request.
Sample REST URL and response: http://restcountries.eu/rest/v1/name/Australia (To see results from different country, change country name in URL).
Plain XML or JSON are not RESTful at all. None of them define any controls(i.e. links and link relations, method information, encoding information etc…) which is against REST as far as messages must be self contained and coordinate interaction between agent/client and service.
Both methods are used by many of the large players. It’s a matter of preference. My preference is REST because it’s simpler to use and understand.
I hope this article has helped you to understand about SOAP and REST services. In next article we teach you how to test these services.
We are always happy to receive any feedback on our articles please feel free to comment.