Call a countries operation
POST
https://api.testingapis.com/api/soap/countriesCall a countries operation: GetCountryInfo or ListCountries.
Namespace http://example.com/countries. For SOAP 1.1 the optional SOAPAction is "http://example.com/countries/GetCountryInfo". ```
<GetCountryInfo xmlns="http://example.com/countries"><countryCode>IN</countryCode></GetCountryInfo> </soap:Body> </soap:Envelope> ```ListCountries takes no arguments and returns the code and name of all 10 countries.
Request body
Optional. text/xml. SOAP 1.1 envelope for GetCountryInfo or ListCountries.
Example body
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetCountryInfo xmlns="http://example.com/countries"><countryCode>JP</countryCode></GetCountryInfo></soap:Body></soap:Envelope>Responses
- 200
- SOAP response envelope.
- 400
- SOAP 1.2 Sender fault (e.g. unknown country code).
- 415
- Content-Type is not text/xml or application/soap+xml.
- 500
- SOAP 1.1 fault.
Example
Request
curl -X POST "https://api.testingapis.com/api/soap/countries" \
-H "Content-Type: text/xml" \
-d '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetCountryInfo xmlns="http://example.com/countries"><countryCode>JP</countryCode></GetCountryInfo></soap:Body></soap:Envelope>'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>
<GetCountryInfoResponse xmlns="http://example.com/countries">
<Country>
<Code>JP</Code>
<Name>Japan</Name>
<Capital>Tokyo</Capital>
<Currency>JPY</Currency>
<PhoneCode>+81</PhoneCode>
<Continent>Asia</Continent>
<Population>124516650</Population>
</Country>
</GetCountryInfoResponse>
… (2 more lines)Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/soap/countries", {
method: "POST",
headers: {
"Content-Type": "text/xml",
},
body: "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetCountryInfo xmlns=\"http://example.com/countries\"><countryCode>JP</countryCode></GetCountryInfo></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/countries",
headers={
"Content-Type": "text/xml",
},
data="<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetCountryInfo xmlns=\"http://example.com/countries\"><countryCode>JP</countryCode></GetCountryInfo></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/countries"))
.header("Content-Type", "text/xml")
.method("POST", HttpRequest.BodyPublishers.ofString("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetCountryInfo xmlns=\"http://example.com/countries\"><countryCode>JP</countryCode></GetCountryInfo></soap:Body></soap:Envelope>"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}