XML in REST vs SOAP APIs

REST and SOAP APIs both use XML, but in very different ways. SOAP requires XML with a strict envelope structure, while REST treats XML as one optional format among many. This post breaks down the key differences with real examples to help beginners navigate both.

XML in REST vs SOAP APIs

When you start working with APIs (application programming interfaces), you'll quickly encounter two terms that seem to come up everywhere: REST and SOAP. Both are ways for software systems to communicate over a network, and both can use XML. But the way they use it is very different. Understanding this distinction will save you a lot of confusion when you're reading API documentation or debugging a failed request.

A Quick Refresher on XML

XML (eXtensible Markup Language) is a format for structuring data using tags, similar to HTML. It wraps data in opening and closing tags to give it meaning and hierarchy. Here is a simple example:

<user>
  <name>Alice</name>
  <role>admin</role>
  <active>true</active>
</user>

This format is human-readable, self-describing, and widely supported across programming languages and platforms. Now let's look at how REST and SOAP each make use of it.

SOAP: XML is Non-Negotiable

SOAP (Simple Object Access Protocol) is a strict, standards-based messaging protocol. One of its defining characteristics is that XML is not optional. Every SOAP message must be formatted as XML, and it must follow a specific envelope structure. There is no alternative data format.

A SOAP message looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <authToken>abc123</authToken>
  </soap:Header>
  <soap:Body>
    <getUserRequest>
      <userId>42</userId>
    </getUserRequest>
  </soap:Body>
</soap:Envelope>

Notice the structure: there is an Envelope, an optional Header, and a Body. This envelope structure is mandatory in every SOAP message. SOAP also relies on a companion standard called WSDL (Web Services Description Language), which is an XML document that formally describes what operations the API supports, what parameters are required, and what responses to expect.

SOAP is commonly found in enterprise environments, banking systems, and legacy integrations where strict contracts and formal error handling matter more than speed and simplicity.

REST: XML is One Option Among Many

REST (Representational State Transfer) is an architectural style for designing networked APIs, not a protocol like SOAP. This is an important distinction. Because REST is a style rather than a strict specification, it doesn't mandate any particular data format. The most common format used with REST APIs today is JSON, but REST can absolutely work with XML as well. The choice is up to the API designer, and sometimes up to the client making the request.

A REST API might accept this XML request body:

POST /users HTTP/1.1
Content-Type: application/xml

<user>
  <name>Bob</name>
  <role>viewer</role>
</user>

And return an XML response. But the same API might also support JSON, switching formats based on the Content-Type and Accept headers in the request. REST is flexible by design.

Key Differences at a Glance

  • Format requirement: SOAP requires XML always; REST can use XML, JSON, plain text, or other formats.
  • Structure: SOAP has a rigid envelope structure; REST XML has no required structure beyond valid XML.
  • Contract definition: SOAP uses WSDL to define the API formally; REST typically uses OpenAPI or informal documentation.
  • Error handling: SOAP has a built-in <soap:Fault> element for structured errors; REST uses HTTP status codes and custom error bodies.
  • Verbosity: SOAP messages tend to be larger and more verbose due to the envelope overhead; REST XML can be leaner.

Which Should You Expect to See?

In modern web development and network automation, you'll encounter REST APIs far more often. Tools like Cisco's RESTCONF interface, the Meraki dashboard API, and most cloud platforms use REST with JSON as the default. However, if you work with older enterprise systems, payment gateways, or telecom platforms, SOAP with XML is still very much alive.

Knowing how to read both formats and understanding why they differ will make you a more versatile developer and a stronger troubleshooter.

Useful Resources

What's Next

Now that you understand how XML fits into REST and SOAP APIs, the next step is learning how to actually parse XML in code. In the next post, we'll look at how Python handles XML data using the built-in xml.etree.ElementTree module, so you can start extracting and working with real API responses programmatically.