API Testing Basics: SOAP API & REST API
The World Wide Web Consortium (W3C) and its collaborators created the messaging standard, SOAP, or Simple Object Access Protocol. XML is used as the data format to define request and answer messages. XML Schema and related technologies ensure the data’s structure and consistency.
What is SOAP API?
SOAP is a common interface used by private and public Application Programming Interfaces (APIs). All types of businesses create and use SOAP APIs, though they are more common in bigger organisations.
Four unique aspects are provided by SOAP, which utilises XML as the data format for messages delivered and received by an API client:
- Envelope: The envelope defines the message’s structure.
- Encoding: Rules for defining the nature of data are called encoding.
- Requests: How is each SOAP API request structured?
- Reactions: How each SOAP API response is structured.
Making SOAP Requests with Postman
In Postman, you should select the HTTP POST method to send a SOAP request. SOAP requests are typically sent using the HTTP POST method because the SOAP message, including the request envelope and data, is included in the body of the POST request. Here’s how to send a SOAP request in Postman:
- Open the Postman application.
- To open an HTTP request, select New > HTTP.
- Enter your SOAP endpoint URL in the address field. For this example, use the following endpoint URL:
https://www.dataaccess.com/webservicesserver/NumberConversion.wso
- From the list of available request methods, choose POST.
Adding body data
- Select raw from the Body tab and XML from the dropdown menu.
- In the text entry field, enter your XML. The following XML should be entered in the text entry box to test the number conversion SOAP API used in the previous section:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<NumberToWords
xmlns="http://www.dataaccess.com/webservicesserver/">
<ubiNum>500</ubiNum>
</NumberToWords>
</soap:Body>
</soap:Envelope>
Your request body must include the SOAP Envelope, Header, and Body tags as required by the endpoint and any namespaces. The data must include the operation’s name and any values you must post to the service.
Setting your request headers
Postman automatically adds an application/xml content-type header when you specify an XML body type. But for some SOAP calls, you may need text/xml, depending on your service provider. To determine which header is suitable, check with your SOAP service. If the text/xml header is required, change Postman’s default configuration.
To set request headers, do the following:
- Open the request Headers. If the auto-generated headers are hidden, select hidden to display them.
- Clear the Content-Type header, which was automatically added.
- Add a new key-value pair, content type, and text/xml.
- Add another key-value pair, SOAPAction and “#MethodName”(in this example, “#POST”).
Sending your request
Select Send to make your call to the SOAP service. Postman displays the response in the lower tab if your call is successful.
If we follow the steps properly, according to the provided request, a response message will be displayed to the user along with the expected result. To identify the response message, please visit the following link and check out what the response message is trying to say:
2 Responses