I am working on Spring Cloud and using the sample project by Josh Long at
Bootiful Microservice by Josh Long
There is an API gateway reservation-client which consumes data from the service reservation-service which provides a HATEOAS response, which then is converted to a simple JSON response.
@RestController
@RequestMapping("/reservations")
class ReservationApiGateway {
Method:
@HystrixCommand(fallbackMethod = "fallback")
@RequestMapping(method = RequestMethod.GET, value = "/names")
public Collection<String> names() {
return this.reservationReader
.read()
.getContent()
.stream()
.map(Reservation::getReservationName)
.collect(Collectors.toList());
}
I modify it to forward me the HATEOAS response like this.
@HystrixCommand(fallbackMethod = "fallback")
@RequestMapping(method = RequestMethod.GET, value = "/names")
public Resources<Resource<Reservation>> names() {
return this.reservationReader
.read();
}
This is giving me a HATEAOS response, but the links are all from the reservation-service - .
"_links" : {
"self" : {
"href" : "**http://192.168.0.3:7000/reservations/1**"
},
"reservation" : {
"href" : "http://192.168.0.3:7000/reservations/1"
}
}
How do I make sure Feign updates the links to the server and port of the API Gateway? - http://192.168.0.3:9999/reservations/1
Same response from reservation-client(same as reservation-service):
{
"_embedded" : {
"reservations" : [ {
"reservationName" : "Josh",
"_links" : {
"self" : {
"href" : "http://192.168.0.3:7000/reservations/1"
},
"reservation" : {
"href" : "http://192.168.0.3:7000/reservations/1"
}
}
}, {
"reservationName" : "Dr. Johnson",
"_links" : {
"self" : {
"href" : "http://192.168.0.3:7000/reservations/2"
},
"reservation" : {
"href" : "http://192.168.0.3:7000/reservations/2"
}
}
}, {
"reservationName" : "Dr. Syer",
"_links" : {
"self" : {
"href" : "http://192.168.0.3:7000/reservations/3"
},
"reservation" : {
"href" : "http://192.168.0.3:7000/reservations/3"
}
}
}, {
"reservationName" : "Dr. Pollack",
"_links" : {
"self" : {
"href" : "http://192.168.0.3:7000/reservations/4"
},
"reservation" : {
"href" : "http://192.168.0.3:7000/reservations/4"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://192.168.0.3:7000/reservations{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://192.168.0.3:7000/profile/reservations"
},
"search" : {
"href" : "http://192.168.0.3:7000/reservations/search"
}
}
}