Spring Data REST is part of the umbrella Spring Data project and makes it easy to build hypermedia-driven REST web services on top of Spring Data repositories.

To add

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

The Spring auto configuration scans all repositories and publish them as REST API

Spring Data REST is using the HATEOAS (Hypermedia As The Engine Of Application State) principle and supports HAL (Hypertext Application Language) as a semantic layer for metadata (like linking) on top of it.

The principle of HATEOAS is that each resource has its own URI (aka endpoint), and you always transfer the whole state of your object behind an endpoint

The other important idea behind this principle is that clients shall only know one entry point to your API and can discover the API without any out of bound information like documentation in a wiki or word file.

RepositoryDetectionStrategy is used to determine which repositories should be exposed in the API.

All these model objects support spring data rest

@Configuration
public class RepositoryConfiguration implements RepositoryRestConfigurer {
    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.exposeIdsFor(BackendTask.class);
        config.exposeIdsFor(GenericRun.class);
        config.exposeIdsFor(JobResume.class);
        config.exposeIdsFor(PlugMillingData.class);
        config.exposeIdsFor(PlugMillingRun.class);
        config.exposeIdsFor(Problem.class);
        config.exposeIdsFor(Run.class);
        config.exposeIdsFor(RunFile.class);
        config.exposeIdsFor(User.class);
        config.exposeIdsFor(WellDetail.class);
        config.exposeIdsFor(FileData.class);
    }
}

 

HAL is a simple format that gives a consistent and easy way to hyperlink between resources in your Rest API.

Adopting HAL will make your API explorable, and its documentation easily discoverable from within the API itself. In short, it will make your API easier to work with and therefore more attractive to client developers.

HAL Browser

You can access the HAL browser by the following generic link

http://<host>:<port>/browser/browser.html.

 

For more info

https://codeboje.de/spring-data-rest-tutorial/

 

Leave a comment

Quote of the week

“People ask me what I do in the winter when there’s no baseball. I’ll tell you what I do. I stare out the window and wait for spring.”

~ Rogers Hornsby

Recent posts

Designed with WordPress