Spring Data REST - Background



In general, if we have to create a REST API or a restful application using Spring, We majorly use SpringMVC module. As a result, a controller gets created, and then we use a service layer which in turn uses the services provided by the Data access layer (DAO). These data access layer uses JPA to connect with the database, which exposes out the database table as restful resources. SO this is the traditional flow to create a restful application. We have to go through the same boilerplate process again and again, no matter how many applications we have to create. Over this, if our application has to support HAL or HATEOAS functionality then we have to write additional code for this in our controller methods. Is not it cumbersome? The good news is that Spring Data rest help us to create a restful application without the above boilerplate process. Before discussing the Spring Data REST in detail lets have some clarity on core concepts.

What is REST

REST stands for REpresentational State Transfer. It is an architectural style principle defined by Roy Fielding in his Ph.D. dissertation in the year 2000. This principle defines a set of guidelines or specifications. Since it is just a specification, so there must be an implementation of it, and that is HTTP. The HTTP is an implementation of REST and it provides a uniform interface to perform CRUD operation using HTTP methods i.e. POST, GET, PUT, and DELETE. Any web application that allows to perform CRUD operation is usually done through an HTTP uniform interface which in turn provides easy access through URI. Uniform interface and easy access is one of the principles of REST. Click here to know more about REST

HAL and HATEOAS

HATEOAS stands for Hypermedia as the engine of application state. It is another principle of a REST. HATEOAS provides a way to navigate through all the restful resources in our application using hypermedia links. HAL stands for Hypertext application language, is an implementation of HATEOAS. HAL provides the exact structure of the responses of an event so that it can navigate to the resources using links. In short HAL is a JSON representation format that provides us a consistent and good way to hyperlink between resources in our res APIs. We will learn more about HAL in the later section of this tutorials.

Advertisements