Resources


Getting started

Add a service 
curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=example-service' \
--data 'url=http://mockbin.org'

Add a route for the service 
curl -i -X POST \
--url http://localhost:8001/services/example-service/routes \
--data 'hosts[]=example.com'

Forward requests through Kong 
curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host: example.com'


More detail:


Add a service:
curl -i -X POST http://localhost:8001/services/ \
-d 'name=foo-service' \
-d 'url=http://foo-service.com'
HTTP/1.1 201 Created
...


{
"connect_timeout": 60000,
"created_at": 1515537771,
"host": "foo-service.com",
"id": "d54da06c-d69f-4910-8896-915c63c270cd",
"name": "foo-service",
"path": "/",
"port": 80,
"protocol": "http",
"read_timeout": 60000,
"retries": 5,
"updated_at": 1515537771,
"write_timeout": 60000
}

This request instructs Kong to register a Service named “foo-service”, which points to http://foo-service.com (your upstream).
Note: the url argument is a shorthand argument to populate the protocol, host, port, and path attributes at once.
Now, in order to send traffic to this Service through Kong, we need to specify a Route, which acts as an entrypoint to Kong:

Add a route:
curl -i -X POST http://localhost:8001/routes/ \
-d 'hosts[]=example.com' \
-d 'paths[]=/foo' \
-d 'service.id=d54da06c-d69f-4910-8896-915c63c270cd'
HTTP/1.1 201 Created
...


{
"created_at": 1515539858,
"hosts": [
"example.com"
],
"id": "ee794195-6783-4056-a5cc-a7e0fde88c81",
"methods": null,
"paths": [
"/foo"
],
"preserve_host": false,
"priority": 0,
"protocols": [
"http",
"https"
],
"service": {
"id": "d54da06c-d69f-4910-8896-915c63c270cd"
},
"strip_path": true,
"updated_at": 1515539858
}
We have now configured a Route to match incoming requests matching the given hosts and paths, and forward them to the foo-service we configured, thus proxying this traffic to http://foo-service.com.


Viewing config

curl  -k -X GET https://localhost:8444 | jq .
curl  -k -X GET https://localhost:8444/services | jq .
curl  -k -X GET https://localhost:8444/routes | jq .