
The curl GET command can be used to determine if a service exists.
On the Kong server
If Kong is running on docker, refer to Kong - Docker container command line for the steps on how to issue commands in the Kong Docker container. Assuming you are using the default kong.conf file, the Kong Admin API will listen on port 8001.
If issuing this command on the Kong server, this command will display Services JSON.
curl --request GET "http://localhost:8001/services"
From a remote server
If issuing this command from a remote server, this command will display Services JSON.
curl --request GET "http://hostname:8000/admin-api/services"
Exact service name unknown
If you do not know the exact name of the service, the following command can be used to determine if there are any services matching a certain string. In this example, we are searching for any service that contains "foo" in the name of the service.
curl --silent --insecure --request GET --url "http://localhost:8001/services" | sed 's|,|\n|g' | grep "\"name\":" | grep -i "foo"
If "foo-service" does not exist, since the --silent option is being used, there should be no output.
If "foo-service" exists, something like this should be displayed.
"name":"foo-service"
Exact service name known
In this example, the cURL command is used to determine if "foo-service" exists.
curl --insecure --request GET --url 'http://localhost:8001/services/example-service'
If the service exists, something like this should be displayed.
{
"host":"www.example.com",
"created_at":1584414186,
"connect_timeout":60000,
"id":"7a2081ea-f4f6-45bf-b9c2-85824d2a34a9",
"protocol":"http",
"name":"foo-service",
"read_timeout":60000,
"port":80,
"path":null,
"updated_at":1584414186,
"retries":5,
"write_timeout":60000,
"tags":null,
"client_certificate":null
}
If the service does not exist, the following JSON shold be displayed.
{
"message":"Not found"
}
100 results
Only the first 100 Services will be returned, starting with the Service that has the lowest numeric ID, and then ascending. The output will include offset, like this.
"offset":"WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"
In this example, you would use the offset to return the next 100 records.
curl --request GET "http://hostname:8000/admin-api/services?offset=WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"
Did you find this article helpful?
If so, consider buying me a coffee over at