2. SOAP APIs

A SOAP API (Simple Object Access Protocol API) is a protocol-based API that allows communication between applications over a network. Unlike REST, which is an architectural style, SOAP is a strict protocol with well-defined standards for message formatting, transport, and error handling. SOAP APIs use XML as their message format and rely on SOAP envelopes to structure requests and responses.

SOAP was designed for enterprise-level systems requiring high security, reliability, and formal standards for communication.

How SOAP APIs Work

SOAP APIs follow a strict messaging structure:

  1. SOAP Request:

    A client sends a request to the server in the form of an XML document, wrapped in a SOAP envelope. The envelope contains the request details, including the action to perform and any necessary parameters.

  2. SOAP Response:

    The server processes the request and responds with another XML document wrapped in a SOAP envelope. This contains the result or error message.

SOAP APIs often use the HTTP/HTTPS protocol for transport, but they can also work with other protocols like SMTP or TCP.

Key Features of SOAP APIs

  1. XML-Based Messaging:

    SOAP exclusively uses XML for its request and response messages, ensuring strict structure and compatibility across different systems.

  2. Protocol-Driven:

    SOAP is a formal protocol with strict rules for structuring messages, error handling, and security.

  3. Transport Independence:

    While SOAP commonly uses HTTP/HTTPS, it can also operate over other protocols like SMTP, FTP, or TCP.

  4. WS-Security:

    SOAP APIs include robust security features (e.g., encryption, authentication) via standards like WS-Security, making them ideal for sensitive data.

  5. Service Definition:

    SOAP APIs require a WSDL (Web Services Description Language) document. The WSDL is an XML-based contract that defines the service, its available methods, and the structure of requests and responses.

  6. Stateful and Stateless:

    Unlike REST, which is stateless, SOAP can support both stateless and stateful operations, depending on the system requirements.

Structure of a SOAP Message

A SOAP message is an XML document divided into several parts:

Example SOAP Request:

<soap:Envelope xmlns:soap="<http://schemas.xmlsoap.org/soap/envelope/>">
  <soap:Header>
    <!-- Optional Header Information -->
  </soap:Header>
  <soap:Body>
    <GetWeather>
      <City>New York</City>
    </GetWeather>
  </soap:Body>
</soap:Envelope>

Example SOAP Response: