Reputation: 3
I have an angular app, requesting data from a Spring Boot backend with Spring Data Rest. Requests to repositories generate responses with HATEOAS structure. But when I ask from Spring MVC controller, the response is indifferent structure(natural).
Is there any example where I can achieve the same structure on a particular controller request? I believe I should implement HATEOAS, but haven't seen a single example.
Upvotes: 0
Views: 253
Reputation: 2429
Find official example here.
The return value of your controller method should be wrapped in EntityModel
or CollectionModel
, so the JSON should be in HAL format.
@PostMapping("/orders")
ResponseEntity<EntityModel<Order>> newOrder(@RequestBody Order order) {
order.setStatus(Status.IN_PROGRESS);
Order newOrder = orderRepository.save(order);
return ResponseEntity //
.created(linkTo(methodOn(OrderController.class).one(newOrder.getId())).toUri()) //
.body(assembler.toModel(newOrder));
}
Upvotes: 1