Understanding SOAP and RESTful Web Services

Nisal Pubudu
Geek Culture
Published in
5 min readMay 14, 2021
Image: REST vs SOAP by: https://www.akana.com/

If you are a software engineer you might already work with at least one of these technologies, unless you are a newcomer to IT industry, who only knows these as popular web services. So whoever you are, this article will help you to understand basic concepts between these 2 technologies. However, before moving into the SOAP and REST we should have basic knowledge about web services.

Web Services

Web services are applications that allow for communication between devices over the internet. These are totally independent of the technology or language the devices are built on, as they use standardized XML for information exchange. A client or user can invoke a web service by sending an XML message and then in turn gets back and XML response message.

Basically, web services include any software, application, or cloud technology that provides standardized web protocols (HTTP or HTTPS) to interoperate, communicate, and exchange data messaging.

So, the main feature of web services is that applications can be written in various languages and they are still able to communicate by exchanging data with one another through a web service between clients and servers.

A web service supports communication among various apps with SOAP, XML, WSDL, and HTML. As an example, XML supposed to tags the data, SOAP transfers the message, and WSDL describes the service’s accessibility.

However, there are different types of web services known as XML-RPC, UDDI, SOAP, and REST. Above all, SOAP and REST are the 2 most popular web services exists at the moment.

SOAP and REST

If you are a well experienced software engineer for years, you may know that IT professionals and web developers have debated over which web service is better. But still, there isn’t a clear winner in this case. Because it always depends on the situation and the use case.

RESTful web services and SOAP offer different variations. For example, a REST web service is generally a better choice when time is a factor, but SOAP wins out when building a service with multiple, non-CRUD methods. But there are some scenarios that both options are consider as the right choice. In many cases, company’s specific requirements determine which type of web service a partner will implement.

However, both SOAP and REST web services are relying on well-established rules that everyone has agreed to follow by in the interest of exchanging information. Now, it’s time to break down each option while exploring their advantages over the another.

SOAP Web Services

SOAP is defined as Simple Object Access Protocol. Microsoft originally developed SOAP to take the place of older technologies that don’t work well on the internet such as the Distributed Component Object Model.

This web service protocol exchanges structured data using XML and generally HTTP and SMTP for transmission. SOAP also uses WSDL (Web Services Description Language) documents to distribute a web service description model. This describes how the SOAP requests (client-side) and responses (server-side) must appear. Also, SOAP web Services have standards for security and addressing.

Image: SOAP Web Service (https://terasolunaorg.github.io/)

Why SOAP’s difficulty depends on programming language?

If you have already used SOAP, you may know that using XML to make requests and receive responses in SOAP can become extremely complex. In some programming languages, you need to build those requests manually, which might become problematic because SOAP is intolerant of errors. However, some languages can use shortcuts that SOAP provides. They can help you reduce the effort required to create the request and to parse the response, like .NET languages. So, that means the difficulty of using SOAP mainly depends on the language you use.

SOAP’s built-in error handling

This is one of the most important features that comes with SOAP. So, if there’s a problem with your request, the response contains error information that you can use to fix the problem. But if there is no feature like that, you may have to keep guessing as to why things didn’t work. The error reporting even provides standardized codes so that it’s possible to automate some error handling tasks in your code.

RESTful Web Service

The acronym REST, stands for REpresentational State Transfer. REST is an architectural style, meaning each unique URL represents an individual object of some sort. A REST web service uses HTTP and supports several HTTP methods: GET, POST, PUT or DELETE. It also offers simple CRUD-oriented services.

So, as you can see REST relies on a simple URL to make a request, instead of using XML. But in some situations, you must provide additional information, but most web services using REST rely exclusively on using the URL approach.

Image: RESTful API (https://dev.to/)

Let’s see an example using basic HTTP requests. In this case we going to use “Swagger Pet Store API” from Swagger.io (https://swagger.io/).

  • Sending a GET request to /pet/{petId} would retrieve pets with a specified ID from the database.
  • Sending a POST request to /pet/{petId}/uploadImage would add a new image of the pet.
  • Sending a PUT request to /pet/{petId} would update the attributes of an existing pet, identified by a specified id.
  • Sending a DELETE request to /pet/{petId} would delete a specified pet.

Note: URL for Swagger Pet Store API -> https://petstore.swagger.io/

So, which one is better?

Before deciding which one is better, let’s see some differences between these two web services.

Soap Advantages

  • Language, platform, and transport independent (REST requires use of HTTP)
  • Works well in distributed enterprise environments
  • Standardized
  • Provides great pre-build extensibility in the form of the WS standards
  • Built-in error handling
  • Automation when used with certain language products

REST Advantages

  • REST is easier to use for the most part and is more flexible
  • No expensive tools require to interact with the web service
  • Smaller learning curve
  • Way more efficient than SOAP (SOAP uses XML for all messages, REST can use smaller message formats)
  • Fast (no extensive processing required)

So, as I mentioned earlier it depends. SOAP has been the preferred option by many companies over the years. However, it is apparently REST that will see a greater acceptance in the future. So, there is no win for either of these two.

So, this is the end of the article and I hope you enjoyed it. Happy Coding👨‍💻.

--

--