Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement hateoas in Quarkus

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.

like image 720
user1601373 Avatar asked Oct 28 '25 03:10

user1601373


1 Answers

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!

like image 134
Jose Carvajal Avatar answered Oct 29 '25 18:10

Jose Carvajal