How to implement hateoas in Quarkus

762 Views Asked by At

I need to migrate our spring boot application to Quarkus. Facing the issue of how to implement the hateoas in Quarkus. Any suggestions are welcome.

Spring boot code:

import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.ControllerLinkBuilder;

    public String getHref(ProductOfferApiRequest productOfferApiRequest) {
        Link link = ControllerLinkBuilder
                .linkTo(ProductOfferingController.class)
                .slash("getProductOrderService")
                .slash(productOfferApiRequest.getRequestHeader().getOrderID())
                .slash(productOfferApiRequest.getRequestHeader().getSessionID())
                .withSelfRel();
        return link.getHref();
        return null;

Looking similar solution in Quarkus.

1

There are 1 best solutions below

0
Jose Carvajal On

For Quarkus RESTEASY Reactive extension, you can also use the dependency "quarkus-resteasy-reactive-links" which gives you support for Web links (hateoas). See the official documentation about this dependency.

If what you're looking for, it's to programmatically access the generated links, then you would need to inject the RestLinksProvider as:

@Inject
RestLinksProvider linksProvider;

And then use the getTypeLinks(class) or getInstanceLinks(instance) to search for the links.

Instead, if what you're looking for, it's to manually generate the links yourself (you want to use the provided @InjectRestLinks and @RestLink annotations as described in the documentation), then you can build the links yourself as follows:

Response response = Response.ok()
            .header("Link", Link.fromUri(...).build())
            .build();

Note that the Link class is a builder with lots of options.

I hope it helps!