Q&A
REST API vs. SOAP
Overview
Both let systems communicate over a network, but they embody different philosophies. SOAP (Simple Object Access Protocol) is a heavyweight, standards-driven protocol. REST (Representational State Transfer) is a set of architectural constraints layered on HTTP. The practical choice usually comes down to: do you need SOAP's formal rigor and built-in enterprise features, or REST's simplicity, performance, and ubiquity?
graph TD
A[Web API approach] --> B[SOAP: protocol]
A --> C[REST: architectural style]
B --> B1[XML only, WSDL contract]
B --> B2[WS-Security, transactions, any transport]
C --> C1[JSON/XML/etc., HTTP verbs]
C --> C2[Stateless, cacheable, lightweight]
style C fill:#1e1b4b,color:#fff
SOAP
- Format: XML only, with a strict envelope (Header + Body).
- Contract: described by WSDL (Web Services Description Language), enabling auto-generated client stubs and strong typing.
- Transport: transport-agnostic - HTTP, SMTP, TCP, JMS.
- Standards (WS-*): built-in specs for security (WS-Security), reliable messaging, and ACID transactions (WS-AtomicTransaction).
- Style: operation/action-oriented (calls like
getUser).
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<getUser><id>42</id></getUser>
</soap:Body>
</soap:Envelope>
REST
- Format: any - JSON is most common; also XML, plain text.
- Resources & verbs: models resources (
/users/42) acted on by HTTP methods:GET(read),POST(create),PUT/PATCH(update),DELETE(remove). - Stateless: each request carries all needed context; no server-side session.
- Cacheable: leverages HTTP caching.
- Lightweight: less overhead than XML envelopes.
GET /users/42 HTTP/1.1
Accept: application/json
200 OK
{ "id": 42, "name": "Ada" }
Side-by-Side Comparison
| Dimension | SOAP | REST |
|---|---|---|
| Type | Protocol | Architectural style |
| Data format | XML only | JSON, XML, etc. |
| Contract | WSDL (formal) | OpenAPI/Swagger (optional) |
| Transport | HTTP, SMTP, TCP… | HTTP/HTTPS |
| State | Can be stateful | Stateless |
| Security | WS-Security (built-in) | HTTPS, OAuth, JWT |
| Caching | Hard | Native via HTTP |
| Overhead | Heavy (XML envelope) | Light |
| Tooling/typing | Strong, code-gen from WSDL | Looser, schema optional |
| Best for | Enterprise, finance, strict contracts | Web/mobile, public APIs, microservices |
When to Choose Which
Choose SOAP when you need formal contracts and code generation, ACID transactions across services, built-in message-level security/standards (common in banking, payments, telecom, healthcare), or must integrate with existing SOAP infrastructure.
Choose REST when you want simplicity, performance, and broad client support (web/mobile), easy caching and scalability, JSON payloads, and a public or microservice API. This is the default for new web development.
Where GraphQL/gRPC Fit
Modern alternatives exist: GraphQL lets clients request exactly the fields they need from one endpoint; gRPC uses Protocol Buffers over HTTP/2 for high-performance internal service-to-service calls. Mentioning these shows current awareness, but REST vs SOAP remains the classic framing.
Why This Matters in Interviews
This is a staple API-design question. Be crisp that SOAP is a protocol (XML, WSDL, WS-* standards, transport-agnostic) and REST is an architectural style (HTTP verbs, resources, stateless, usually JSON). The strongest answers are non-dogmatic: REST for most modern web/mobile, SOAP for enterprise scenarios needing strict contracts/security/transactions. Naming the HTTP verb→CRUD mapping and statelessness as REST hallmarks is expected.
Common Pitfalls
- Calling REST a "protocol" - it's an architectural style; SOAP is the protocol.
- Claiming SOAP is "old/obsolete" - it's still chosen where formal contracts and WS-Security matter.
- Forgetting REST's statelessness and cacheability constraints.
- Conflating "REST" with "any JSON-over-HTTP API" (true REST has specific constraints).
References
- MDN HTTP methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
- Roy Fielding's REST dissertation: https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm