Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-service linking for HATEOAS micro-services

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

like image 342
keaplogik Avatar asked Nov 10 '14 23:11

keaplogik


1 Answers

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.

like image 151
bvulaj Avatar answered Oct 22 '22 19:10

bvulaj