Kong
Install via Docker
# Start your database
$ docker run -d --name kong-database \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
postgres:9.5
# Prepare your database
$ docker run --rm \
--link kong-database:kong-database \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
kong:latest kong migrations up
# Start Kong
$ docker run -d --name kong \
--link kong-database:kong-database \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-e "KONG_ADMIN_LISTEN_SSL=0.0.0.0:8444" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong:latest
Install Dashboard
$ docker network create kong-dashboard
$ docker network connect kong-dashboard kong
$ docker run --rm --network kong-dashboard -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
Admin API (:8001)
- Create a service name "api-svc" on api getway
$ curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=api-svc' \
--data 'url=http://192.168.10.10:8888/' \
--data 'port=8888' \
--data 'path=api-svc'
- Add a router for the service
$ curl -i -X POST \
--url http://localhost:8001/services/api-svc/routes \
--data 'paths[]=/foo'
$ curl -i -X DELETE http://localhost:8001/routes/{id}
$ curl -i -X DELETE http://localhost:8001/services/{name or id}
$ curl -i -X PATCH http://localhost:8001/services{name or id}
--data 'name=api-svc' \
--data 'path=api-svc' \
--data 'port=8888' \
--data 'url=http://192.168.10.10:8888/'
- You cat check your configure via browser
http://localhost:8001/routes
http://localhost:8001/services
$ curl -i -X POST \
--url http://localhost:8001/services/api-svc/plugins/ \
--data 'name=key-auth'
$ curl http://localhost:8000/foo/version
{"message":"No API key found in request"}
$ curl -i -X POST \
--url http://localhost:8001/consumers/ \
--data "username=Jason"
$ curl -i -X POST \
--url http://localhost:8001/consumers/Jason/key-auth/ \
--data 'key=test#1234'
- Verify api key for Restful api
$ curl -i -X GET http://localhost:8000/foo/version \
--header "apikey: test#1234"
Reference: