
Kong is a service that sits between a client and a server, such as a web server, an application server, an FTP server. For example, let's say you want to route requests to www.example.com through Kong. In this scenario, you could create a route and a service that would be used to route requests onto www.example.com.
This assumes Kong has been secured with Role Based Access Control (RBAC) and you have created your Kong-Admin-Token. The following curl command can be used to list the endpoints that can be used with the API.
curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/endpoints"
Something like this should be returned. Notice that the /workspace_/services endpoint can be used.
{
"data": [
"/",
"/acls",
"/acls/{acls}",
"/acls/{acls}/consumer",
"/services",
"/services/{services}",
"/services/{services}/application_instances",
"/services/{services}/application_instances/{application_instances}",
"/services/{services}/applications",
"/services/{services}/client_certificate",
"/services/{services}/degraphql/routes",
"/services/{services}/degraphql/routes/{degraphql_routes}",
"/services/{services}/degraphql_routes",
"/services/{services}/degraphql_routes/{degraphql_routes}",
"/services/{services}/document_objects",
"/services/{services}/document_objects/{document_objects}",
"/services/{services}/graphql-rate-limiting-advanced/costs",
"/services/{services}/graphql_ratelimiting_advanced_cost_decoration",
"/services/{services}/graphql_ratelimiting_advanced_cost_decoration/{graphql_ratelimiting_advanced_cost_decoration}",
"/services/{services}/oauth2_tokens",
"/services/{services}/oauth2_tokens/{oauth2_tokens}",
"/services/{services}/plugins",
"/services/{services}/plugins/{plugins}",
"/services/{services}/routes",
"/services/{services}/routes/{routes}",
"workspace_/services",
"workspace_/services/{services}",
"workspace_/services/{services}/application_instances",
"workspace_/services/{services}/application_instances/{application_instances}",
"workspace_/services/{services}/applications",
"workspace_/services/{services}/client_certificate",
"workspace_/services/{services}/degraphql/routes",
"workspace_/services/{services}/degraphql/routes/{degraphql_routes}",
"workspace_/services/{services}/degraphql_routes",
"workspace_/services/{services}/degraphql_routes/{degraphql_routes}",
"workspace_/services/{services}/document_objects",
"workspace_/services/{services}/document_objects/{document_objects}",
"workspace_/services/{services}/graphql-rate-limiting-advanced/costs",
"workspace_/services/{services}/graphql_ratelimiting_advanced_cost_decoration",
"workspace_/services/{services}/graphql_ratelimiting_advanced_cost_decoration/{graphql_ratelimiting_advanced_cost_decoration}",
"workspace_/services/{services}/oauth2_tokens",
"workspace_/services/{services}/oauth2_tokens/{oauth2_tokens}",
"workspace_/services/{services}/plugins",
"workspace_/services/{services}/plugins/{plugins}",
"workspace_/services/{services}/routes",
"workspace_/services/{services}/routes/{routes}"
]
}
In this example, the services in the "foo" workspace will be listed.
curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/foo/services"
If the workspace does not exist, something like this should be returned.
{
"message": "Workspace 'foo' not found"
}
Assuming the workspace exists, if the workspace does not contain any services, something like this should be returned.
{
"data": [],
"next": null
}
If the workspace contains one or more services, something like this should be returned.
{
"data": [
{
"ca_certificates": null,
"client_certificate": null,
"connect_timeout": 20000,
"created_at": 1608760251,
"host": "fooapi.foo-service.svc",
"id": "0d38f6df-d6a5-4b0c-9cc3-d9d4f1447fe7",
"name": "foo-service",
"path": null,
"port": 443,
"protocol": "https",
"read_timeout": 20000,
"retries": 5,
"tags": null,
"tls_verify": null,
"tls_verify_depth": null,
"updated_at": 1608760251,
"write_timeout": 20000
}
],
"next": null
}
Or you can specify the service you want to list.
curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/foo/services/foo-service"
The date command can be used to convert the created_at and updated_at epoch strings to human readable output.
~]$ date -d @1608760251
Wed Dec 23 15:50:51 CST 2020
100+ results
If you have more than 100 services, the REST API will only return the first 100 services and the output will include offset, like this.
"offset":"WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"
You would then use the offset to return the next 100 services.
curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/services?offset=WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"
Postgres
Undeneath the hood, the services are stored in the services table in the Kong Postgres database.
~]# psql --username postgres --dbname kong --command "select * from services" --expanded
-[ RECORD 1 ]-
id | e4adf0f1-6832-4294-a0f8-dfc18342f512
created_at | 2022-09-15 18:59:50+00
updated_at | 2022-09-15 18:59:50+00
name | my-service
retries | 5
protocol | https
host | fooapi.foo-service.svc
port | 443
path |
connect_timeout | 20000
write_timeout | 20000
read_timeout | 20000
tags |
client_certificate_id |
tls_verify |
tls_verify_depth |
ca_certificates |
ws_id | 67313229-d967-48c6-b512-bcbbe9688f84
enabled | t
Did you find this article helpful?
If so, consider buying me a coffee over at