I'm developing a system in a microservices architecture using java8 and Spring Cloud. I implemented a post rest controller that receives an object in json and then saves it in the database. The problem is; how do I get the URI containing the API Gateway of the just saved object so I can return it on the created responde body?
Like, when I use URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(savedProfile.getId()).toUri(); I get http://Boss.mshome.net:8081/profile/1 instead of localhost:8765/nukr-profile-service/profile/1 which is the endpoint with the API Gateway's path.
What's the best practice to retrieve this URI?