SOAP API | SOAP API Example Protocol | SOAP APIs Interface | Stoplight (2023)

SOAP is an important protocol that helped introduce the widespread use of Web Services, also called APIs. Based on XML,the SOAP protocol is still in wide usage. Many organizations use the more flexible REST API pattern, but others preferthe structure, datatype control, and defined standard of SOAP.

This guide will cover an introduction to SOAP APIs, including how to call them, how to describe them, and other commontopics that will help you understand the basics of the protocol’s history and place within Web Service APIs.

What is SOAP

SOAP is the Simple Object Access Protocol, a messaging standard defined by the World Wide Web Consortium and its membereditors. SOAP uses an XML data format to declare its request and response messages, relying on XML Schema and othertechnologies to enforce the structure of its payloads.

Both public and private Application Programming Interfaces (APIs) use SOAP as an interface. While more popular in largeenterprises, organizations of all sizes produce and consume SOAP APIs.

SOAP is uses the Remote Procedure Call (RPC) pattern, where functions or methods are passed parameters and return aresult. Many RPC solutions prior to SOAP were dependent on specific programming languages or technology stacks. Forexample, previous RPC implementations often required both sides of the RPC to use the C programming language, whichpredates the modern Internet. Even an Internet-era language, Java, has its own RPC model called Remote Method Invocation(RMI), which originally was tightly coupled with the Java Virtual Machine (JVM).

Among the important aspects of SOAP APIs are their independence from programming language and even underlying transportprotocol. The sender can use C#, for example, while the recipient’s stack relies on Java. While these moreenterprise-oriented languages are most common with SOAP, there are SOAP implementations in Python, Ruby, and all modernprogramming languages.

A final advantage to SOAP is its extensibility. As a standard, its specification is deliberately limited on constraints.As such, the extensibility model within the SOAP specification provides for customization.

How to Call a SOAP API

In order to call a SOAP API, you’ll most likely need to include a SOAP library with your programming language. Althoughit’s possible to make SOAP API calls without SOAP libraries, it’s more efficient to work with an abstraction rather thancrafting the messages yourself. The SOAP messages are verbose, mainly due to reliance on XML.

While the following examples use Python for readability, remember that SOAP is agnostic regarding your programminglanguage. To retrieve a user profile from a fictitious SOAP API, you might make the following request using the Zeeplibrary:

(Video) API Web Services Beginner Tutorial 4 - What are SOAP Web Services

preparing...

In this example, we initiate a SOAP client based upon the SOAP endpoint. Then we call the service, invoking thegetuser option with a user ID parameter. It’s a simple example, but disguises even more detail of the SOAP messagesbehind the scenes.

Let’s look at how this SOAP call might be structured:

preparing...

And the response might look something like this:

preparing...

(Video) How to connect to Salesforce using SOAP APIs ? | SOAP UI Tutorial

Even in this simple example, the actual data within the message is surrounded by the SOAP structure. Compared to somemore modern API request examples, SOAP may appear overly complex. Keep in mind that most developers making SOAP APIcalls are using a library, which provides a friendlier interface.

That said, it is possible to make SOAP API calls through a typical HTTP request (most SOAP services use HTTP, though thespecification is independent of protocol). Here is the same call above using the Python requests library:

preparing...

In this case, response.content would include the raw XML response, which needs to be parsed in order to determine theusername and any other data the SOAP API returns.

Anatomy of a SOAP Message

The examples in the above sections have already shown the format of SOAP API messages. In this section, you can betterunderstand the few blocks of XML that SOAP requests contain. While it’s deliberately minimal (the “S” in SOAP stands for“simple,” after all), it provides the foundation for complex implementations.

SOAP messages are constructed of up to four blocks:

  • soap:Envelope
  • soap:Header
  • soap:Body
  • soap:Fault

Only soap:Envelope and soap:Body are required. However, each plays an important role in SOAP APIs. Below, each ofthese SOAP constructs is covered separately.

SOAP Envelope

SOAP uses XML, but needs a way to separate it from other XML documents. The soap:Envelope tag provides a mechanism toidentify the XML as SOAP.

(Video) How to do SOAP API requests in Python

In addition, the soap:Envelope tag requires a namespace attribute(xmlns:soap="https://www.w3.org/2003/05/soap-envelope/" for the latest version of SOAP) and can optionally supply anencodingStyle attribute.

The entirety of the SOAP message comes within the envelope, including the other three blocks.

SOAP Header

In the basic SOAP API examples shown in earlier sections, the header was empty. While it’s optional, soap:Header makespossible SOAP’s extensibility via SOAP Modules. These modules can either be required or optional. In the case that theyare required, you can include the mustUnderstand attribute set to true.

SOAP Body

As implied by the name and shown in examples, soap:Body contains the bulk of the SOAP message. Namespaces can be usedto describe what data to expect within the body, but are not required. In practice, the name of the procedure,parameters, and data all come through the SOAP Body.

SOAP Fault

Finally, the soap:Fault tag is used within the soap:Body tag for error messages when a SOAP API call is not able tocomplete. There are many possible causes for an error, including inaccurate SOAP formatting, a processing error on theserver, and mismatched data type.

To communicate the many errors, there are several sub-elements that can be present within the Fault tag:

  • Code: a machine-readable error code
  • Reason: a human-readable error reason
  • Node: the SOAP node where the error occurred
  • Role: the role of the SOAP node where the error occurred
  • Detail: application-specific error details, with both human- and machine-readable data

While soap:Fault is optional, a SOAP implementation is not truly complete without encapsulating potential errors usingthis tag.

Use a WSDL to Describe a SOAP API

As SOAP and other Web Services became ubiquitous, many tools, technologies, and standards were created to support them.Among them is the Web Services Description Language (WSDL), an XML format that describes how to call a web service. Itdefines the operations available and what input/output fields to expect.

Though not specific to SOAP, many implementations of SOAP APIs combine a WSDL with XML Schema to provide a robust webservice for exchanging messages using defined procedures and field types. Because a WSDL is machine-readable, a SOAPclient could determine what operations are possible, what data is needed to complete the call, and then present a userwith the data needed.

(Video) Web Services Testing using SOAP UI

WSDLs are also used to generate human-readable documentation for SOAP APIs. Developers can look at the method names andinput to determine what’s required to call the SOAP API. In addition, some programming language libraries and developerenvironments can consume a WSDL file to help programmers with available methods and syntax when writing code.

Like SOAP, WSDL is general enough for many types of usage, though the two technologies are frequently used together.

SOAP API Security

Many SOAP API examples, such as those to query stock quotes or weather, have no authentication. While useful for a quickproof of concept, more robust SOAP APIs will authenticate and authorize the API calls, ensuring that important businessprocesses are only available to approved parties.

As with any API or web service, there are many ways to handle security within SOAP APIs. Since many SOAP APIs use HTTP,it’s possible to piggyback on other authentication and authorization schemes within that protocol.

For example, HTTP Basic Auth accepts a username and password. When sent via SSL/TLS, this can be a barebones way toauthenticate a user. However, there is no built-in role or authorization with this method. In addition, while itprovides point-to-point security, often end-to-end security is required.

WS-Security is a SOAP extension that provides a number of security features for SOAP APIs. Built on top of the XMLEncryption and XML Signature specifications, WS-Security describes how to sign and encrypt SOAP messages. In addition,it supports a handful of security token formats, including SAML, X.509, and Kerberos.

Perhaps SOAP’s most used extension, WS-Security enables end-to-end security, authorization of senders, and otherfeatures enterprises require in web services.

History and Future of SOAP

The first SOAP specification was published in 2000. An earlier version, released in 1998, was known as XML-RPC and had amore focused feature set. Like SOAP, XML-RPC allows for remote procedure calls via XML. XML-RPC specifically only usesHTTP to transport the data. While this is the common protocol for SOAP, as well, SOAP can technically use any protocol.

It took three years for the SOAP specification to reach recommendation stage. Quickly it became the most common approachto web services. Prior to SOAP, there was not a standards-based approach to creating programmable interfaces forexchanging data between systems. SOAP helped shepherd innovation both within the enterprise and encouraged the firstwave of public APIs from companies like eBay, Salesforce, and Amazon.

(Video) Postman Tutorial - SOAP API Requests with Postman

Around the same time, REST APIs were described in a doctoral dissertation. However, SOAP’s embrace as a standard, aswell as its application in industry (contrasted with academia), helped it remain the popular choice for much of thedecade.

SOAP remains important as a standard for web services and runs many internal systems worldwide. For new projects, manyorganizations are moving to microservices architecture using REST APIs. While the more modern techniques leave behind afully standards-based approach of SOAP, many prefer the more flexible and nimble development process.

Compare SOAP vs REST to see the differences and similarities betweenthese two approach to web services.

FAQs

What is SOAP API with example? ›

SOAP is the Simple Object Access Protocol, a messaging standard defined by the World Wide Web Consortium and its member editors. SOAP uses an XML data format to declare its request and response messages, relying on XML Schema and other technologies to enforce the structure of its payloads.

What is SOAP protocol example? ›

Simple Object Access Protocol (SOAP) is a lightweight XML-based protocol that is used for the exchange of information in decentralized, distributed application environments. You can transmit SOAP messages in any way that the applications require, as long as both the client and the server use the same method.

What is SOAP VS API? ›

An API is designed to expose certain aspects of an application's business logic on a server, and SOAP uses a service interface to do this while REST uses URIs. While SOAP APIs are designed after the functions that the API exposes, REST APIs are designed after the data.

What communication protocol does SOAP use? ›

It uses XML Information Set for its message format, and relies on application layer protocols, most often Hypertext Transfer Protocol (HTTP), although some legacy systems communicate over Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission.

What are the 3 types of APIs? ›

Today, there are three categories of API protocols or architectures: REST, RPC and SOAP. These might be dubbed "formats," each with unique characteristics and tradeoffs and employed for different purposes. REST.

Is SOAP a REST or HTTP? ›

While SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. The rules in SOAP are important because we can't achieve any level of standardization without them. REST as an architecture style does not require processing and is naturally more flexible.

Is REST and SOAP a protocol? ›

Representational state transfer (REST) is a set of architectural principles. Simple object access protocol (SOAP) is an official protocol maintained by the World Wide Web Consortium (W3C). The main difference is that SOAP is a protocol while REST is not.

What is difference between HTTP and SOAP protocol? ›

SOAP and HTTP are both communication protocols. But SOAP is messaging protocol concerned with packaging of messages in XML protocol and transfer then using HTTP . HTTP is used solely used to transfer information over the internet. You can get much more information over internet.

Is REST API a protocol? ›

REST is a set of architectural constraints, not a protocol or a standard. API developers can implement REST in a variety of ways. When a client request is made via a RESTful API, it transfers a representation of the state of the resource to the requester or endpoint.

What is SOAP API in simple terms? ›

Simple Object Access Protocol (SOAP) is a message specification for exchanging information between systems and applications. When it comes to application programming interfaces (APIs), a SOAP API is developed in a more structured and formalized way.

Which API is better SOAP or REST? ›

REST is a better choice for simple, CRUD-oriented services, because of the way REST repurposes HTTP methods (GET, POST, PUT, and DELETE). It is also popular because it's lightweight and has a smaller learning curve. SOAP, on the other hand, has standards for security, addressing, etc.

How does SOAP protocol works? ›

How Does SOAP Work? The SOAP specification describes a standard, XML-based way to encode requests and responses, including: Requests to invoke a method on a service, including in parameters. Responses from a service method, including return value and out parameters.

What two messages does SOAP communicate? ›

SOAP supports two possible communication styles: – remote procedure call (RPC) and – document (or message). A remote procedure call (RPC)-style Web service appears as a remote object to a client application.

Which of protocols are supported by SoapUI? ›

Moreover, SoapUI supports all of the major protocols such as SOAP, REST, JMS, JDBC, WSDL, JSON, and XML, etc.

What is difference between API and APIs? ›

The key distinction is that web services are a type of API: All web services are APIs, but not all APIs are web services. 'API' is the broader category because, by definition, it refers to any software component that acts as an intermediary between two otherwise disconnected applications.

What are protocols in API? ›

An API protocol defines the rules for API calls: it specifies accepted data types and commands. Different API architectures specify different protocol constraints.

Can SOAP work without HTTP? ›

Using an underlying transport protocol other than HTTP: SOAP is independent of an underlying transport protocol, so you don't have to use HTTP. Instead, you could use SMTP (Simple Mail Transfer Protocol) or JMS (Java Messaging Service) or another transport protocol, depending on your application.

Can we call REST service in SOAP? ›

You can import your REST service in SoapUI by using WADL files. Besides, ReadyAPI supports the OpenAPI, Swagger and RAML formats. Your basic REST HTTP requests are: POST, GET, PUT, and DELETE.

Is SOAP a JSON or XML? ›

The content of a SOAP message is XML data, whereas a JSON message contains JSON data. JSON and XML are different encoding mechanisms for describing structured data. JSON tends to be a more efficient encoding mechanism, so a typical JSON message will be smaller than the equivalent XML message.

What is the most common soap? ›

Dove is a personal care brand owned by Unilever, it is also the most popular brand name in the soap markets across over 80 countries in the world.

Which protocol uses REST? ›

REST is web standards based architecture and uses HTTP Protocol. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000.

What is a REST API example? ›

An application implementing a RESTful API will define one or more URL endpoints with a domain, port, path, and/or query string — for example, https://mydomain/user/123?format=json . The HTTP method.

Is SOAP a TCP or UDP? ›

SOAP is a protocol specification for exchanging structured information in the implementation of Web Services. It uses XML for the message format. It is independent of the transport protocol (could be HTTP, FTP, TCP, UDP, or named pipes). SOAP based services strictly define the format of messages passed back and forth.

Why would you use SOAP instead of HTTP? ›

SOAP provides the following advantages when compared to REST: Language, platform, and transport independent (REST requires use of HTTP) Works well in distributed enterprise environments (REST assumes direct point-to-point communication) Standardized.

Can JSON be used with SOAP? ›

SOAP can use JSON for communication, but the reverse is not at all possible. SOAP uses XML format, whereas JSON uses a key-value pair. The error message can be declared with SOAP, but the same is not possible with JSON. Comparison between JSON vs SOAP.

Is SOAP an application layer protocol? ›

SOAP (Simple Object Access Protocol) is the foundational, XML-based application protocol used to implement Web services within a SOA (Service Oriented Architecture).

What is SOAP and why it is used? ›

Soap is a salt of a fatty acid used in a variety of cleansing and lubricating products. In a domestic setting, soaps are surfactants usually used for washing, bathing, and other types of housekeeping. In industrial settings, soaps are used as thickeners, components of some lubricants, and precursors to catalysts.

What is difference between SOAP and JSON? ›

There are some important differences between SOAP and JSON: The content of a SOAP message is XML data, whereas a JSON message contains JSON data. JSON and XML are different encoding mechanisms for describing structured data.

What are the three components of SOAP? ›

The three main constituents of soap are Lye (Sodium hydroxide), coconut oil and water.

Is SOAP a TCP or HTTP? ›

SOAP (Simple Object Access Protocol) is a message protocol that enables the distributed elements of an application to communicate. SOAP can be carried over a variety of standard protocols, including the web-related Hypertext Transfer Protocol (HTTP).

How does SOAP work for dummies? ›

When you mix soap with dirt and water, the soap molecules break up the dirt and the bacteria it contains by forming circles around individual droplets—the fatty chains go in the middle facing the dirt, while the salt balloon tops form the outside of the circle facing the surrounding water.

How do I call a SOAP API? ›

Select the Headers tab and add the Content-Type key with the text/xml value. Click on the Body tab, select raw and XML and enter your SOAP message in the input field. That's pretty much it. Afterwards, you should see if your request was successful (hopefully you received a 200 HTTP response).

Do people still use SOAP protocol? ›

These days, most public web services provide REST APIs and transfer data in the compact and easy-to-use JSON data interchange format. However, enterprise users still frequently choose SOAP for their web services.

How many types of soap are there? ›

Did you know there are three different methods of Soap Making? Cold process, melt and pour, and hot process. There are pros and cons for each method and every maker has their own personal preference.

Videos

1. REST vs SOAP | Differences between SOAP and Rest Web Services | NodeJS Training | Edureka
(edureka!)
2. JMeter Beginner Tutorial | How to create SOAP API Request
(Automation Step by Step)
3. JAVA - Send SOAP XML Request and Read Response
(jinu jawad m)
4. SOAP APIs | API Testing
(نظام Nezam)
5. Creating a SOAP API | Software AG
(SOFTWARE AG)
6. Understand the Difference Between SOAP and REST APIs
(SmartBear)
Top Articles
Latest Posts
Article information

Author: Lidia Grady

Last Updated: 03/04/2023

Views: 5857

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.