What is REST – RESTful API Fundamentals for Java Developers
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
REST stands for Representational State Transfer. It is an architectural style: a set of design constraints for systems in which clients, servers, and other network components exchange representations of resources. REST is not a Java library, a Spring annotation, HTTP itself, or a JSON format. HTTP is commonly used because its methods, status codes, headers, and caching rules fit REST well.
For example, /orders/42 can identify an order. GET /orders/42 asks for a representation of its current state. One client may receive JSON and another may receive a different supported format, but both are working with the same resource. The URI can remain stable even if the server changes its Java classes or database tables.
REST combines several constraints. Client-server separation keeps user-interface concerns apart from data and service concerns. Statelessness means each request carries the context needed to understand it. Cache rules tell clients and intermediaries whether a response may be reused. A layered system allows components such as gateways and proxies. The uniform interface gives requests and responses shared meaning. Code-on-demand is optional and allows a server to extend a client by sending executable code.
The uniform interface is the part often missed in everyday “REST API” examples. It covers identifying resources, changing them through representations, sending self-descriptive messages, and using hypermedia controls to show available next actions. A controller that returns JSON may follow useful REST conventions, but JSON and CRUD routes alone do not prove that the full REST style is being followed.
What is REST – RESTful API Fundamentals for Java Developers
Direct Answer
REST (Representational State Transfer) is an architectural style for client-server systems. An API is RESTful when its interactions follow REST's mandatory constraints, including stateless requests, responses that declare their cache rules, a uniform interface, and layered components. Code-on-demand is optional. Using HTTP and returning JSON is common, but those choices alone do not make an API RESTful.
Deep Dive & Architecture
The plain meaning
REST describes how parts of a networked application communicate. It does not tell us which Java framework to use or which database to choose. Instead, it limits the way components interact so that clients, servers, and intermediaries can understand the same messages and change independently.
The six constraints
- Client-server: the client deals with the user experience, while the server owns resources and business work. Each side can change without knowing the other's internal code.
- Stateless: every request contains the context needed to understand it. The server does not rely on a hidden conversation from an earlier request.
- Cache: every response says whether it may be reused and, when allowed, under which rules. Correct caching can reduce repeated work and network traffic.
- Uniform interface: resources and messages follow shared rules instead of a private command language for every endpoint.
- Layered system: a client can communicate through a gateway, proxy, or cache without needing to know the full path to the origin server.
- Code-on-demand: a server may send executable code that extends a client. This is the only optional constraint.
The four parts of the uniform interface
- Identify resources: a URI identifies the resource involved in an interaction.
- Manipulate resources through representations: a client sends a representation of the state it wants or receives a representation of the current state.
- Use self-descriptive messages: the method, status, headers, media type, and message rules provide enough meaning to process the message.
- Use hypermedia for next actions: a representation can include controls that tell the client which transitions are available from the current state.
An order as a REST resource
The URI /orders/42 identifies an order resource. A response to GET /orders/42 transfers a representation of that order and uses HTTP metadata to explain the result. The method gives the request meaning, the status code gives the outcome, Content-Type describes the representation, and cache fields describe reuse. Links can identify valid next actions. None of this requires the client to know the server's controller class or table name.
Where “REST API” becomes imprecise
Using HTTP methods, noun-based paths, and JSON is a useful start, but it is not the complete REST definition. In particular, REST's uniform interface includes hypermedia: the response can tell the client what it may do next. Many practical APIs adopt only part of this style. That can be a sensible engineering choice, but “REST-style HTTP API” is a more precise name when important constraints are intentionally missing.
Code Example
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, max-age=60
ETag: "order-v7"
{
"id": 42,
"status": "pending",
"total": 1999,
"links": [
{"rel": "self", "href": "/orders/42"},
{"rel": "cancel", "href": "/orders/42/cancellation"}
]
}
HTTP gives standard meaning to the status, Content-Type, cache rule, and opaque ETag validator. The JSON field names and link relations are application-defined, so application/json alone does not explain their meaning; the API still needs a documented contract or a media type that defines those semantics.
Check your understanding
Answer these without looking back at the article.
- Which REST constraint is optional?
- Why does JSON alone not make an API RESTful?
- What are the four parts of the uniform-interface constraint?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.