Cross-service linking for HATEOAS micro-services
Asked Answered
V

1

11

I have a number of micro-services built with Spring Boot, so for a bit of fun, I thought I'd have a go at adding HATEOAS to them to help set up cross-resource linking. It seems to work quite nicely within a particular project, but I was wondering whether there's a good way to link across APIs. As an example, imagine I have 3 services:

A user details service: Code:

/users/{userid}

A user calendar service: Code:

/users/{userid}/appointments
/users/{userid}/appointments/{appointmentid}

A user messaging service: Code:

/users/{userid}/messages
/users/{userid}/messages/{messageid}

To make this browsable via the API, it would be good to have links from a user resource to its appointments and messages. Similarly, it would be nice to have links back from those resources. This is all very achievable when I have a single API with everything on the classpath, where I can write code such as:

Code:

user.add(linkTo(methodOn(CalendarController.class).appointments(user.getKey())).withRel("appointments"))

However I'm not able to do this if CalendarController is not on the classpath of the service I'm currently hitting.

Is there a good/recommended method for creating links to controllers which are not in the current project?

Referenced from spring forums

Vallie answered 10/11, 2014 at 23:33 Comment(3)
we have the EXACT same problem. We've considered having a JAR that defines paths and sharing that along with resources that expose paths and having the APIs talk to each other. both solutions have drawbacks. Can't wait to see any answers about thisFinality
Yes same here. We are thinking of developing our own DSL for building and sharing links. In our use case the links will be shared to a zookeeper node that the services can then request links to other resources. If Spring HATEOAS offers a solution now or in the near future, it would be nice to follow down that path eventually.Vallie
I think we are asking about the same thing. #27791405Implead
O
2

Maybe this is a bit more involved than you were hoping, but as mentioned here, this is exactly what Eureka is for. It also has really nice integration with the new Spring Cloud project.

Overestimate answered 20/2, 2015 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.