Table of contents
How can you choose between SOAP, REST and GRaphQL, what are the differences between SOAP, REST And GraphQL ? We will look at what it means and the distinctions between the three main types of web services: SOAP, REST, and GRaphQL. In doing so, I hope you’ll learn a few things about these technologies and find something interesting to follow up on in future searches.
What is SOAP?
SOAP stands for Simplified Object Access Protocol. It was originally designed in 1990 for exchanging data across different applications written in different programming languages by providing a simple XML-based messaging format that is easy for programmers to read and write. SOAP allows for remote procedure calls (RPCs) to be made over HTTP.
These RPCs are typically implemented using HTTP POST calls, but can also be implemented using other HTTP methods. SOAP servers are very popular in enterprise environments where the large number of applications and systems require consistent call interface definitions, or to enable applications written in different programming languages to communicate.
Why was SOAP replaced?
It was largely replaced by REST due to the excessive size of web services created using SOAP, this is why REST is so commonly used in mobile applications which use fewer server-side resources than desktop applications. Due to this, it is also less popular than other types of web service (see later for GraphQL).
What is REST?
REST stands for Representational State Transfer. It is a set of architectural constraints for designing a web service that uses HTTP methods that emulate the semantics of their web-based counterparts. It was created in 1997 by Roy T. Fielding to describe a set of principles of good design for stateless, location-independent systems applied to the World Wide Web.
REST is a key decision criterion of both SOAP and GraphQL. REST uses resources established using the HTTP verbs GET, POST and PUT, meaning they eschew XML-based communication, which is better for simple querying operations but less suited to more advanced messaging scenarios. A resource is identified by its URI, which can be used in programmatic communication or data retrieval operations. Read more about APIs here.
As you can see above, REST is not just an HTTP style of web service, but also a set of architectural constraints for designing Web Services.
What is GraphQL?
GraphQL is a query language for APIs. It is used mainly on the server-side to manage Graph Database models.
GRaphQL is a programmatic query language for accessing REST APIs that can be used to create RESTful apps. GRaphQL allows the developer to implement complex queries to fetch data from all conceivable parts of an API. This means fetching data from clients, services, other APIs and even other GraphQL servers all at once, this is known as Graph Mirroring. The result is a single source of truth for your data allowing automated updates without manual intervention.
How have the technologies advanced over the years?
Over the years, web services have progressed quite a lot, especially when you compare modern-day web services with SOAP. It’s not just SOAP that has improved, however – the other two technologies have also seen improvements over time. SOAP is no longer in use, although it’s important to be able to recognize it when you see it.
REST has also become more popular over the years, for example, are quite a few websites using REST, for example, GitHub uses REST heavily. GraphQL is still pretty new, however, so not all businesses will have started using it yet.
GraphQL was made in 2015 by Facebook so it’s only in the past couple years that GraphQL has been used. SOAP was popular in 2006/2007 but then due to its massive size it decreased in popularity over time, however, SOAP is not entirely irrelevant because modern-day web services are based on SOAP’s design principles.
GraphQL is only really relevant to mobile applications because of its size, REST is often used in mobile applications because of its simplicity and ease of use, whereas SOAP is mostly used in larger Enterprise/Enterprise-like systems where many companies are sharing data.
After researching these technologies and understanding what they are, it is clear that they all have their own strengths and weaknesses. GraphQL is great for just defining your data structure and allows you to query for it. REST provides a lot of flexibility such as creating APIs, but it’s not always the easiest to work with.
Which one should you use?
If you’re building simple web services, especially if they are for mobile applications, then REST will be the simplest choice. If you’re building large enterprise web services, then SOAP/REST would be fine to use. If you require complex queries and data retrieval then REST easily falls short of what GraphQL can do.
This is why it’s important to understand what technologies are available to provide web services for you or your business.
Read more about why we need APIs here