Spring HATEOAS Linking to Another Service
Asked Answered
V

0

12

Spring HATEOAS works great at linking to another method in the same application. For example:

Greeting greeting = new Greeting(String.format(TEMPLATE, name));
greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel());

If one were to implement a microservice architecture, then most of the linked methods would be part of a different service and different Java project.

The only way I can see of to add a link to a method outside of the existing project is to hard-code in the URL (or put it in an external configuration).

Are there any alternatives to dynamically create the URL? For instance, is it possible to use Spring HATEOAS in conjunction with a Service Registry (like Eureka)?

Venterea answered 25/10, 2016 at 23:5 Comment(7)
" then most of the linked methods would be part of a different service and different Java project" Absolutely not. Can you explain your reasoning?Betoken
@zeroflagL Using a microservice architecture, all services are developed and deployed independently of each other. microservices.io/patterns/microservices.htmlVenterea
Sure, but why would a resource of one microservice point to a resource of another one? And even if, why would one service create the URL to / for another one? That makes no sense. And yes, Spring offers integration with Eureka.Betoken
Simple example is a Customer service and an Order service. They are 2 separate microservices. On the Order service, you may want to add a link to the Customer service so the client knows how to access information on the Customer.Venterea
Good example. But if you create an order for a customer you already need a link to the customer. The order service does not create one.Betoken
I know this is old, but still relevent, what if you are running in AWS and you generate a file in S3 and want to return a pre-signed URL for example. Would you return the full URI to this in HATEOS still with a restful response or return a 202 and set the location header?Havener
how is it that there is still no answer?Maze

© 2022 - 2024 — McMap. All rights reserved.