I have created a custom spring-boot actuator health endpoint for my application. Spring boot aggregates all these custom health endpoints into a one big json and returns it when I hit application/health url. Now I want to pass some information to the custom health end point that I have implemented in form of a header when I hit the application/health url. How can I achieve this?
0
votes
Could you elaborate why you want to do that?
– Wim Deblauwe
I want to send a string to this custom healthEndpoint as header and based on this string I want to take decision on which flow of code to follow.
– Kunal gupta
Do you mean that you want to show different health information at the endpoint depending on this header? Why is that? Do you want to hide some health info in some cases?
– Wim Deblauwe
I will explain with an example. If i pass "test" as header then i need to create a mock of a service and returns an http Response. If the header is anything other than "test" then i need to call the actual service and get the response. It's more like an if-else scenario depending on the header that i receive.
– Kunal gupta
Have you considered using a Spring profile to either start a mock service or real service when your application starts?
– Wim Deblauwe
1 Answers
0
votes
If you at all want to pass a header , you might consider hitting the API (a GET API in this case) from any RestClient like PostMan or Insomnia. Simply hitting the url from the browser is actually making a GET request but you can only add path or request parameters in the url, for adding a request body or headers,you will need to use a REST client, or alternatively do it from the command line using curl. Also, after reading the comments,i think what you need is,is to set spring.profile property and determine your code flow based on that- here's how you can set the profile- 1) set Java System Properties (VM Arguments)
java -jar -Dspring.profiles.active=test myapp.jar
2) set Program arguments
java -jar application.jar --spring.profiles.active=test