REST API vs Web Service – Java Backend Interview
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
“Web service” is an overloaded term. In everyday team discussions, it can mean any service that another program calls over a network, so a REST API fits inside that broad category. The W3C Web Services Architecture uses a narrower definition: the service has a machine-processable interface described in WSDL and exchanges SOAP messages, typically over HTTP. In that context, people are really comparing REST with SOAP.
A REST API is defined by an architectural style. It identifies resources, transfers representations, keeps interactions stateless, defines cache behavior, and uses a uniform interface. HTTP is the usual protocol because its methods, status codes, headers, and media types provide much of that shared meaning. JSON is common, but it is not what makes the API RESTful.
The same order lookup shows the difference. A REST-style interface can use GET /orders/42: the URI identifies the order and GET supplies standard read semantics. A SOAP service can send a GetOrder operation inside a SOAP XML envelope, with the message shape described by a service contract. Both may return order 42; their public interaction models are different.
Neither label guarantees that a system is fast, secure, reliable, or transactional. Those properties depend on authentication, transport protection, retries, timeouts, message rules, and implementation choices. The precise conclusion is: with the everyday broad meaning, a REST API is one kind of web service; with the W3C SOAP/WSDL definition, REST APIs and web services refer to separate interface styles.
REST API vs Web Service – Java Backend Interview
Direct Answer
The term web service is used in two ways. In everyday team discussions, it can mean any network service used by another program. The W3C Web Services Architecture uses a narrower definition: the service has a machine-processable interface described in WSDL and exchanges SOAP messages, typically over HTTP. A REST API follows REST's constraints and uniform interface. Under the everyday broad meaning it is a kind of web service, but it is not a SOAP web service.
Deep Dive & Architecture
Why this question causes confusion
“Web service” does not have one meaning in every team. In everyday development, it can mean any service that one program calls over a network. Under that broad meaning, REST APIs, SOAP services, and other network APIs can all be called web services.
The W3C Web Services Architecture uses a narrower historical meaning: a software system with a machine-readable service description, specifically WSDL, whose messages follow that description and use SOAP. Many enterprise interviews use “web service” in this narrower sense. When they do, the real question is REST versus SOAP.
What defines a REST API
A REST API is defined by REST's architectural constraints, not by a file format. It works with identified resources and representations, keeps interactions stateless, provides cache information, supports layers, and uses a uniform interface. In a complete REST interaction, messages are self-descriptive and hypermedia can show the client which transitions are available.
Most REST APIs use HTTP because HTTP already defines method semantics, status codes, headers, media types, caching, and conditional requests. REST does not require JSON. A resource may be represented as JSON, XML, HTML, an image, or another suitable media type.
What defines a SOAP service
SOAP 1.2 defines an XML messaging framework. Its envelope contains a header and body and can carry an application operation such as GetOrder. WSDL is commonly used to describe the available operations, message types, and service location. SOAP messages are often carried over HTTP, but SOAP supplies its own message model rather than using the REST uniform interface.
The correct comparison depends on the term
With the broad meaning, “REST API” is a more specific term inside “web service.” With the narrow enterprise meaning, REST API and SOAP web service are different styles. Neither style automatically provides security, speed, reliability, or transaction safety. Those qualities come from the complete protocol, standards, and system design—not from the label alone.
Code Example
A REST-style request identifies the order resource:
GET /orders/42 HTTP/1.1
Host: api.example.com
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, max-age=60
{"id":42,"status":"PAID","total":1499}
A SOAP 1.2 service can model the same capability as an operation inside an XML envelope:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<GetOrder xmlns="https://example.com/orders">
<id>42</id>
</GetOrder>
</env:Body>
</env:Envelope>
Both interfaces can return order 42. The first uses a resource identifier and HTTP's uniform semantics. The second uses a SOAP message whose application operation and XML types may be described by WSDL. The difference is the public contract, not the business data being requested.
Check your understanding
Answer these without looking back at the article.
- Why can a REST API be called a web service?
- Why does returning JSON not make an API RESTful?
- How would the answer change if web service means SOAP/WSDL in that organization?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.