Hello all, I am trying to retrieve all the services from the Kong using rest Api [‘http://localhost:8001/services’, configured Kong using docker desktop]. I could fetch them successfully, but I have seen the field ‘host’ in the services wherein we can pass the target URL directly or even we can pass the upstream name. Do we have any particular parameter that says whether target url or upstream name is passed over there?
A)
I don’t think there is a parameter for that.
But if you already have an api-call to retrieve a service, you can make an additional call to the endpoint “http://localhost:8001/upstreams” and check if the value is an upstream.
If not (you got a 404 error), then the value is a hostname, otherwise it is an upstream and you have to retrieve it’s targets.
This is also more or less what Kong internally does. For instance here, in “balancers.lua”
By the way: remember that an upstreams don’t have one host, but rather an array of hosts (targets) so it’s better to prepare all calls for an array.
B)
Another solution (or workaround) for this problem is to name all upstreams according to a naming convention. In this case you would be able to distinguish it by the name (this is how we do it in our project). But this is not a general solution.
Thanks Matu. Thanks for your response.