Bootstrap FreeKB - Kong Community Edition (KongCE) - create a Route using REST API
Kong Community Edition (KongCE) - create a Route using REST API


The curl POST command can be used to create a route. This assumes you have already created a service. If not, refer to Kong - create service using cURL. Let's say you've created a service named "foo-service".


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 create a route to "foo-service".

curl -X POST "http://localhost:8001/services/foo-service/routes" --data "hosts[]=www.example.com"

 

Or like this.

curl -X POST "http://localhost:8001/routes" --data "hosts[]=www.example.com"  --data "service.name=foo-service"

 


From a remote server

If issuing this command from a remote server, this command will create a route to "foo-service".

curl -X POST "http://hostname:8000/admin-api/services/foo-service/routes" --data "hosts[]=www.example.com"

 

Or like this.

curl -X POST "http://hostname:8000/admin-api/routes" --data "hosts[]=www.example.com" --data "service.name=foo-service"

 


Validation

If the route was successfully created, something like this should be displayed. Additionally, the cURL command can be used to ensure the route exists.

{
 "id":"273f688a-95c0-4471-9b8d-ae28bae818ef",
 "path_handling":"v0",
 "paths":null,
 "destinations":null,
 "headers":null,
 "protocols":["http","https"],
 "methods":null,
 "snis":null,
 "service":{"id":"f46a60f8-68b7-4e43-ba20-5f50b9e18278"},
 "name":null,
 "strip_path":true,
 "preserve_host":false,
 "regex_priority":0,
 "updated_at":1584415903,
 "sources":null,
 "hosts":["www.example.com"],
 "https_redirect_status_code":426,
 "tags":null,
 "created_at":1584415903
}



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b49d0f in the box below so that we can be sure you are a human.