O'Reilly logo

Spring MVC Cookbook by Alex Bretet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building links for a hypermedia-driven API

In this recipe, we will focus on how to create links with Spring HATEOAS and how to bind them to resources.

We will detail the resource assemblers, which are reusable transition components used to pass from entities (such as Index) to their resources (IndexResource). These components also provide support for link creation.

How to do it…

  1. The created resources (IndexResource, ChartResource, ExchangeResource, IndustryResource, MarketResource, and so on) are created from their associated Entity (Index, ChartIndex, ChartStock, Exchange, Industry, Market, and so on) using resource assemblers registered as @Component:
    import static org.sfw.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.sfw.hateoas.mvc.ControllerLinkBuilder.methodOn; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required