项目作者: itsmurugappan

项目描述 :
高级语言: Java
项目地址: git://github.com/itsmurugappan/APIGateway.git
创建时间: 2017-03-09T00:26:33Z
项目社区:https://github.com/itsmurugappan/APIGateway

开源协议:

下载


Kong API Gateway

This repo has some of my poc’s on Kong on how to set it up and how to use plugins.

Install Cassandra

  1. # kong needs Postgres or Cassandra as datastore. Install if not present
  2. $ docker run -d --name kong-database \
  3. -p 9042:9042 \
  4. cassandra:2.2

Install and start Kong

  1. # Link cassandra and start kong
  2. $ docker run -d --name kong \
  3. --link kong-database:kong-database \
  4. -e "KONG_DATABASE=cassandra" \
  5. -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
  6. -e "KONG_PG_HOST=kong-database" \
  7. -p 8000:8000 \
  8. -p 8443:8443 \
  9. -p 8001:8001 \
  10. -p 7946:7946 \
  11. -p 7946:7946/udp \
  12. kong
  13. # osx install
  14. download the .pkg from https://getkong.org/install/osx/
  15. # before starting open the config at /etc/kong/kong.conf and check the datastore config
  16. # if file not present make a copy of default file and rename to kong.conf
  17. # start kong
  18. $ kong start -c /etc/kong/kong.conf --vv
  19. # check status
  20. $ curl 127.0.0.1:8001

Add your API

  1. # start apache-cxf-jax-ws-demo (SOAP) and producer (REST) projects
  2. # i have httpie installed, not a must curl will do
  3. # i have the admin api running at 8003 instead of 8001
  4. # 2 methods to add api
  5. # Method1: Request Host
  6. $ http POST localhost:8003/apis name=resttest1 upstream_url=http://localhost:8079/counter request_host=resttest1.com
  7. # test
  8. $ http http://localhost:8002 Host:resttest1.com
  9. # Method2: Request Path
  10. $ http POST localhost:8003/apis name=resttest2 upstream_url=http://localhost:8079 request_path=/counter
  11. # test
  12. $ http get http://localhost:8002/counter
  13. # add SOAP service, for test use soap ui
  14. $ http POST localhost:8003/apis name=soaptest1 upstream_url=http://localhost:8080 request_path=/HelloWorld
  15. # get list of api's
  16. $ http GET localhost:8003/apis
  17. # List of commands are available at getkong.org

Add key Auth

  1. $ http POST http://localhost:8003/apis/soaptest1/plugins name=key-auth
  2. $ http POST http://localhost:8003/apis/resttest2/plugins name=key-auth

Add Consumers

  1. $ http POST http://localhost:8003/consumers/ username=soapuser1 custom_id=1
  2. $ curl -X POST http://localhost:8003/consumers/soapuser1/key-auth -d ''
  3. $ http POST http://localhost:8003/consumers/ username=restuser1 custom_id=2
  4. $ curl -X POST http://localhost:8003/consumers/restuser1/key-auth -d ''
  5. # post with apikey header
  6. $ http get http://localhost:8002/counter apikey:xxxx

ACL

  1. # Restrict user access based on groups
  2. $ http POST http://localhost:8003/apis/soaptest1/plugins name=acl config.whitelist=soapgroup
  3. $ http POST http://localhost:8003/consumers/soapuser1/acls group=soapgroup
  4. $ http POST http://localhost:8003/apis/resttest2/plugins name=acl config.whitelist=restgroup
  5. $ http POST http://localhost:8003/consumers/restuser1/acls group=restgroup
  6. # through soapuser1 key u cannot access the rest service

Dashboard

  1. # community project distributed over NPM
  2. # Install Kong Dashboard
  3. $ npm install -g kong-dashboard
  4. # To start Kong Dashboard on a custom port
  5. $ kong-dashboard start -p [port]
  6. # available in the below url
  7. http://localhost:port/