New in 2.4: Test runs you can trust See what's new →

Call a calculator operation

POSThttps://api.testingapis.com/api/soap/calculator

Call a calculator operation: Add, Subtract, Multiply or Divide.

SOAP 1.1: send Content-Type: text/xml and SOAPAction: "http://tempuri.org/Add" (optional; if sent, it must name the operation in the body). ```

<Add xmlns="http://tempuri.org/"><intA>5</intA><intB>3</intB></Add> </soap:Body> </soap:Envelope> ` SOAP 1.2: send Content-Type: application/soap+xml with the same body, using the http://www.w3.org/2003/05/soap-envelope namespace.

The response is <AddResponse><AddResult>8</AddResult></AddResponse>, using the same SOAP version as the request. Errors come back as SOAP Faults. SOAP 1.1 faults always use 500. SOAP 1.2 uses 400 for Sender faults and 500 for Receiver faults. Divide by zero is a Server/Receiver fault. DTDs are rejected.

Parameters 1

NameTypeDescription
SOAPActionheader · stringSOAP 1.1 action, e.g. "http://tempuri.org/Add". Not used for SOAP 1.2.

Request body

Optional. text/xml, application/soap+xml. SOAP 1.1 envelope (send SOAPAction). SOAP 1.2 uses application/soap+xml.

Example body
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Add xmlns="http://tempuri.org/"><intA>5</intA><intB>3</intB></Add></soap:Body></soap:Envelope>

Responses

200
SOAP response envelope.
400
SOAP 1.2 Sender fault (bad input).
415
Content-Type is not text/xml or application/soap+xml.
500
SOAP Fault (all SOAP 1.1 faults; SOAP 1.2 Receiver faults).

Example

Request
curl -X POST "https://api.testingapis.com/api/soap/calculator" \
  -H "Content-Type: text/xml; charset=utf-8" \
  -H 'SOAPAction: "http://tempuri.org/Add"' \
  -d '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Add xmlns="http://tempuri.org/"><intA>5</intA><intB>3</intB></Add></soap:Body></soap:Envelope>'
Run in Studio
Response200 OK
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddResponse xmlns="http://tempuri.org/">
      <AddResult>8</AddResult>
    </AddResponse>
  </soap:Body>
</soap:Envelope>

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/soap/calculator", {
  method: "POST",
  headers: {
    "Content-Type": "text/xml; charset=utf-8",
    "SOAPAction": "\"http://tempuri.org/Add\"",
  },
  body: "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Add xmlns=\"http://tempuri.org/\"><intA>5</intA><intB>3</intB></Add></soap:Body></soap:Envelope>",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/soap/calculator",
    headers={
        "Content-Type": "text/xml; charset=utf-8",
        "SOAPAction": "\"http://tempuri.org/Add\"",
    },
    data="<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Add xmlns=\"http://tempuri.org/\"><intA>5</intA><intB>3</intB></Add></soap:Body></soap:Envelope>".encode("utf-8"),
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/soap/calculator"))
            .header("Content-Type", "text/xml; charset=utf-8")
            .header("SOAPAction", "\"http://tempuri.org/Add\"")
            .method("POST", HttpRequest.BodyPublishers.ofString("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Add xmlns=\"http://tempuri.org/\"><intA>5</intA><intB>3</intB></Add></soap:Body></soap:Envelope>"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}