Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Compare REST over HTTP with JSON and SOAP web services: contract, message format, error handling, tooling and security standards. When would you still choose SOAP today?

SOAP sends XML envelopes described by a WSDL contract and XSD types, reports errors as standard SOAP faults, and has message-level security standards such as WS-Security. REST over HTTP uses resource URIs, HTTP methods and status codes, usually with JSON, an optional OpenAPI contract, problem details for errors, and TLS plus OAuth for security. We still choose SOAP when partners, banks or governments publish WSDL contracts, or when messages must be signed or encrypted end to end.

Why this question is asked

REST with JSON is the default for new APIs, but SOAP is far from dead: payment networks, insurers, tax authorities and many enterprise systems still publish SOAP services, and Java developers regularly have to call or maintain them. Interviewers ask this comparison to see whether we understand both styles on their own terms, rather than just repeating that SOAP is old. In this answer, we will compare the two on contract, message format, error handling, security and tooling, with an example of the same call in both styles, and then see when SOAP is still the right choice.

1A Quick Recap of Both Styles

REST is an architectural style, not a protocol. In practice it means that we expose resources at URIs, such as /customers/42, and act on them with HTTP methods: GET to read, POST to create, PUT or PATCH to change, DELETE to remove. The HTTP status code says how it went, and the body is usually JSON.

SOAP is a protocol. Every message is an XML document with a fixed structure called an envelope, which has an optional header and a body. Most SOAP services send all calls as HTTP POST to a single endpoint URL; the operation name is inside the XML, not in the URL or the method. HTTP is just the transport, and SOAP can in principle run over other transports too.

2The Same Call in Both Styles

Here is a request to fetch customer 42, first as REST and then as SOAP.

Java
GET /customers/42 HTTP/1.1
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{"id": 42, "name": "Ada Lovelace"}
POST /services/CustomerService HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "getCustomer"
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:c="http://example.com/customers">
<soap:Header/>
<soap:Body>
<c:getCustomer><c:id>42</c:id></c:getCustomer>
</soap:Body>
</soap:Envelope>

Notice where the meaning lives. In REST, the method and the URI say what we want, so caches, proxies and logs understand the call. In SOAP, everything is inside the body, and the HTTP layer only sees a POST. The SOAP version is more verbose, but it is also completely self-describing, and the header is a standard place for security tokens, signatures and routing information.

3Contracts: WSDL and XSD Against OpenAPI

A SOAP service is defined by a WSDL file (Web Services Description Language). It lists the operations, the messages each one takes and returns, and the endpoint address, and it uses XSD (XML Schema) to define the types precisely, including lengths, patterns and enumerations. The contract is not optional: SOAP tooling is built around it, and a client is normally generated from it.

REST has no built-in contract. OpenAPI fills that role today: a YAML or JSON file describing paths, methods, schemas and security, from which docs and clients can be generated. The difference is that OpenAPI is optional and can be written after the fact, so its quality varies from one API to the next, while a SOAP service without a WSDL is practically unusable.

4Errors: SOAP Faults Against Status Codes

SOAP reports errors with a fault: a standard element in the body with a code, a human-readable reason and an optional detail element for application data. In SOAP 1.1 the fault comes back with HTTP 500, whatever the cause. REST uses the status code itself to classify the error, 404 for a missing resource or 409 for a conflict, and puts the details in the body, ideally as problem details (RFC 9457, application/problem+json).

XML
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Customer 42 not found</faultstring>
<detail><c:errorCode>CUST-404</c:errorCode></detail>
</soap:Fault>
</soap:Body>
HTTP/1.1 404 Not Found
Content-Type: application/problem+json
{"type": "https://api.example.com/errors/customer-not-found",
"title": "Customer not found", "status": 404, "detail": "Customer 42 not found"}

Both are structured. The SOAP fault is guaranteed by the protocol, so every SOAP client knows how to read it. Problem details are a standard too, but a REST API may still return any body it likes on error, so clients must check what each API actually does.

5Security Standards and Tooling

This is the biggest practical difference. SOAP has the WS-* family of standards. WS-Security lets the sender sign parts of the message and encrypt them inside the XML, with timestamps against replay, so the protection travels with the message through any number of intermediaries and can be stored as evidence. WS-ReliableMessaging and others cover delivery guarantees. REST relies on the transport and on tokens: TLS protects the connection, and OAuth 2 access tokens, often JWTs, carry identity. Once TLS ends at a load balancer, the message itself is no longer protected unless we add something like JWS signatures on top.

In Java, SOAP is served by Jakarta XML Web Services (formerly JAX-WS) implementations such as Apache CXF and Eclipse Metro, or by Spring Web Services, which is contract-first and fits well into Spring Boot. JAX-WS and JAXB used to ship inside the JDK, but they were removed in Java 11, so today we add them as dependencies, using the jakarta namespace with current versions. REST in Spring means Spring MVC or WebFlux on the server, and RestClient, WebClient or HTTP interfaces on the client.

REST over HTTP against SOAP
AspectREST over HTTPSOAP
ContractOpenAPI, optionalWSDL with XSD types, required in practice
MessageUsually JSON; URI and method carry meaningXML envelope, header and body; usually POST
ErrorsStatus codes and problem detailsStandard SOAP fault element
SecurityTLS, OAuth 2 tokens, optional JWSWS-Security signing and encryption in the message
Java toolingSpring MVC, RestClient, springdocJakarta XML Web Services (CXF, Metro), Spring WS
Caching, browsersHTTP caching, easy from JavaScriptHardly cacheable, awkward from browsers

6When We Would Still Choose SOAP

For a new API between our own services or for web and mobile clients, REST or gRPC is almost always the better choice: lighter, easier to call, and better supported by browsers, gateways and observability tools.

SOAP is still the right answer in two situations. The first is integration: when a bank, a payment scheme, an insurer or a government agency publishes a WSDL, we call it as SOAP, and if we are the one exposing a service to partners who already integrate that way, offering SOAP may be a contractual requirement. The second is message-level security: when each message must be signed, possibly encrypted, and kept as non-repudiable evidence, WS-Security gives us a mature standard that both sides' tooling already supports.

7Follow-up questions

Is SOAP always slower than REST?

XML is larger and slower to parse than JSON, and WS-Security adds signing and canonicalisation work, so SOAP messages cost more CPU and bandwidth. For most business integrations that difference is small compared with network and database time; it matters mainly at very high volumes.

Can a REST API have a strict contract like WSDL?

Yes. With design-first OpenAPI, server interfaces generated from the spec, request validation and breaking-change checks in CI, a REST API can be as strictly defined as a SOAP service. The difference is that REST leaves this to our discipline, while SOAP tooling assumes it from the start.

What is the difference between SOAP 1.1 and 1.2?

SOAP 1.2 uses a different envelope namespace and the application/soap+xml content type, has a more structured fault with Code and Reason elements, and allows different HTTP status codes for faults. Both are still in use, and the WSDL tells us which one a service expects.

8Conclusion

In this answer, we compared REST over HTTP with JSON and SOAP. SOAP uses an XML envelope, a WSDL contract with XSD types, standard faults and the WS-* standards such as WS-Security for message signing and encryption. REST uses URIs, methods and status codes, usually JSON, optional OpenAPI contracts, problem details, and TLS with OAuth for security. In Java, SOAP lives on through Jakarta XML Web Services implementations and Spring Web Services, since JAX-WS left the JDK in Java 11. We still choose SOAP for partners who publish WSDL contracts and when message-level signing is required.

What to say in the interviewAbout 80 seconds aloud

Open with

REST over HTTP exposes resources at URIs and uses HTTP methods and status codes, usually with JSON, and the contract, typically OpenAPI, is optional. SOAP is a protocol: every message is an XML envelope with a header and a body, usually POSTed to one endpoint, and the contract is a WSDL with XSD types, which in practice is required because clients are generated from it.

Then, if they want more

For errors, SOAP has a standard fault element; REST uses the status code to classify the error and ideally problem details in the body. The biggest difference is security. SOAP has WS-Security, so the message itself can be signed and encrypted, with timestamps, and that protection survives intermediaries; REST relies on TLS for the connection and OAuth tokens for identity.

In Java, SOAP is done with Jakarta XML Web Services implementations like Apache CXF or Metro, or with Spring Web Services; JAX-WS and JAXB were removed from the JDK in Java 11, so they come in as dependencies with the jakarta namespace. For new APIs I would choose REST or gRPC.

I would still choose SOAP when integrating with banks, insurers or governments that publish WSDL contracts, or when every message must be signed for non-repudiation and WS-Security is the standard both sides already support.

About this answer

Last updated
12 November 2026
Versions it names
Java 11
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare REST over HTTP with JSON and SOAP web services: contract, message format, error...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/c5444716f1/