For the latest stable version, please use Spring Data REST 4.4.0!spring-doc.cn

Tools

The HAL Explorer

Kai Tödter has created a useful application: HAL Explorer (Git Repo, Reference Doc, Demo). It is an Angular based web application that lets you easily explore HAL and HAL-FORMS based HTTP responses. It also supports Spring profiles generated by Spring Data REST. You can point it at any Spring Data REST API and use it to navigate the app and create new resources.spring-doc.cn

Instead of pulling down the files, embedding them in your application, and crafting a Spring MVC controller to serve them up, all you need to do is add a single dependency.spring-doc.cn

The following listing shows how to add the dependency in Maven:spring-doc.cn

<dependencies>
  <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-rest-hal-explorer</artifactId>
  </dependency>
</dependencies>

The following listing shows how to add the dependency in Gradle:spring-doc.cn

dependencies {
    implementation 'org.springframework.data:spring-data-rest-hal-explorer'
}
If you use Spring Boot or the Spring Data BOM (bill of materials), you do not need to specify the version.

This dependency auto-configures the HAL Explorer to be served up when you visit your application’s root URI in a browser. (NOTE: localhost:8080/api was plugged into the browser, and it redirected to the URL shown in the following image.)spring-doc.cn

hal explorer 1

The preceding screenshot shows the root path of the API. On the right side are details from the response, including headers, and the body (a HAL document).spring-doc.cn

The HAL Explorer reads the links from the response and puts them in a list on the left side. You can either click on the green GET button and navigate to one of the collections, or click on the other buttons to make changes (POST, PUT, PATCH) or delete resources.spring-doc.cn

The HAL Explorer understands URI Templates. Whenever a link contains a URI template, a modal dialog pops up where you can enter the template parameters.spring-doc.cn

hal explorer 3

If you click Go! without entering anything, the variables are essentially ignored. For situations like Projections and Excerpts or Paging and Sorting, this can be useful.spring-doc.cn

When you click on a NON-GET button with a + or a > sign on it, a modal dialog appears. It shows the HTTP method belonging to the clicked button. You can fill the body and submit the new JSON document.spring-doc.cn

Below the URI and HTTP method are the fields. These are automatically supplied, depending on the metadata of the resources, which was automatically generated by Spring Data REST. If you update your domain objects, the pop-up reflects it, as the following image shows:spring-doc.cn

hal explorer 2