Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 26, 2025
REST is a software architectural style that relies on rules that describes how to define and access resources. As we can see on Google Trends, interest in REST is huge. It’s hard to imagine the moderns Internet without RESTful APIs. In this article, we’ll dive deeply into REST and related HTTP concepts.
As we mentioned, the REST is a software architectural style. On the other hand, it isn’t standardized (like SOAP). It gives a lot of elasticity as it comes to implementation. For example, there is no single and appropriate way to implement pagination. Therefore, REST defines a set of main, general constraints to follow while developing RESTful APIs. Let’s define them.
Considering REST we usually think of HTTP-based applications. Although, it’s possible to use REST for different protocols but it happens very rarely. Thus, in this section, we’ll focus on HTTP protocol and its usage with REST.
To begin with, an HTTP protocol is the protocol of the World Wide Web. It defines the rules of communication between a client and a server. HTTP is stateless and it works in a request-response approach.
A client sends a request related to some resource. It can be an HTML website, a file, or javascript code. HTTP doesn’t define what a resource should be. Each resource has its own identifier calls URI. A general structure of URI looks as follows:
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
To clarify, let’s see a real-world example:
The URI is only a part of the HTTP request. The request consists of:
We already know, that the HTTP request consists of the request line and there is the HTTP method. The HTTP method describes the action that the client wants to perform on the resource. There are four basic, most used methods: GET, POST, PUT, and DELETE. Let’s define them.
The first one, GET is used to read the resource. The server returns the resource for the given URI. The GET method doesn’t contain a body. It only fetches the resource and doesn’t modify it in any way.
The second one, POST is used to transfer data to the server. Thus, it’s usually associated with creating a resource. The data are sent in the body. After the resource is created, the server should respond with its URI.
The next one, PUT is similar to POST. Although, it differs significantly. It’s used to update the existing resource. It overrides the whole resource with transferred data. The main property, that differs PUT from POST, is that PUT is an idempotent operation. That means calling PUT with the same data many times will always give the same result. It doesn’t have any side effects. Moreover, PUT points to an existing resource. Whereas POST creates a new one.
The final basic method is DELETE. As the name suggests, it’s used to delete an existing resource.
There are also additional methods, that could be sometimes used: PATCH, HEAD, OPTIONS, CONNECT, and TRACE. Although, there are rarely used and we won’t cover them in this article.
The HTTP response comes with the response code. It informs about the result of the operation. It’s especially useful for UI developers, as they can perform appropriate action basing on the code. There are the following groups of HTTP response codes :
In simple words, the Richardson Maturity Model estimates the level of compliance with the requirements of the RESTful API. The model defines four levels. If the API meets all of them that means it fully implements the model. Thus, it indicates that the API is of good quality considering the REST constraints.
Level 0 is called The Swamp of POX. On that level, API doesn’t use the full potential of the HTTP protocol, usually, it uses POST and GET methods only. Thus, the HTTP protocol is only used as a transport layer. Moreover, mostly response codes 200 are returned. Further, the implementation doesn’t rely on well-defined URIs. Example endpoints of level 0 API could look as follows:
POST /api/createUser
POST /api/updateUser
GET /api/findUser
The level 1 API defines resources and their URIs. Although, still additional HTTP methods and response codes aren’t used. The example URIs of level 1 API are:
POST /api/users/create
GET /api/users/{id}/find
POST /api/users/{id}/update
On level 2 API uses additional HTTP methods besides GET and POST such as PUT, PATCH, or DELETE. Therefore, URIs are better defined. Moreover, API uses more meaningful HTTP response codes. Below, we can see an example level 2 API endpoints:
POST /api/users
PUT /api/users/{id}
GET /api/users/{id}
Finally, level 3 introduces HATEOAS. it’s a self-navigating API. It adds some complexity, thus it’s not often used. In simple words, we add URIs of additional resources related to the demanded resource. To clarify, let’s look at the below example. In a user response, we embedded an address URI and by using it the client can fetch the address details.
{
"id":12345,
"firstname":"some-firstname",
"lastname":"some-lastname",
"age":39,
"links":{
"address":"users/12345/address"
}
}
In this article, we defined REST architecture fundamentals and constraints. Moreover, we described HTTP protocol and its usage in RESTful APIs. We can see, that REST is solid and elastic architecture. Therefore, it’s so popular and widely used in many modern APIs.