【Kong】API 操作简解

1. Upstreams

  • 创建
curl -X POST http://127.0.0.1:8001/upstreams --data "name=exampleUpstream"
  • 查询
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/upstreams/exampleUpstream --data "tags[]=tag1" --data "tags[]=tag2"
  • 删除
curl -i -X DELETE --url http://127.0.0.1:8001/upstreams/exampleUpstream
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/upstreams?size=10

2. Target

  • 创建
curl -X POST http://127.0.0.1:8001/upstreams/exampleUpstream/targets --data "target=www.baidu.com:80" --data "weight=100"
  • 查询
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80 --data "tags[]=tag1" --data "tags[]=tag2"
  • 删除
curl -i -X DELETE --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets/www.baidu.com:80
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/upstreams/exampleUpstream/targets

3. Service

  • 创建
curl -i -X POST --url http://127.0.0.1:8001/services --data 'name=example' --data 'url=http://www.baidu.com'
  • 查询
curl -i -X GET  --url http://127.0.0.1:8001/services/example
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/services/example --data 'retries=10' --data 'connect_timeout=80000'
  • 删除
curl -i -X DELETE --url http://127.0.0.1:8001/services/example
  • ALL
curl -i -X GET --url http://127.0.0.1:8001/services?size=10

4.Routes

  • 创建
curl -i -X POST --url http://127.0.0.1:8001/services/example/routes --data 'name=ft' --data 'hosts[]=baidu.com' --data 'paths[]=/first'
  • 查询
curl -i -X GET  --url http://127.0.0.1:8001/services/example/routes/ft
  • 更新
curl -i -X PATCH --url http://127.0.0.1:8001/services/example/routes/ft --data 'request_buffering=false' --data "tags[]=tag1" --data "tags[]=tag2"
  • 删除
curl -i -X DELETE  --url http://127.0.0.1:8001/services/example/routes/ft
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/routes?size=10

5.Consumers

  • 创建
curl -i -X POST --url http://127.0.0.1:8001/consumers --data "username=jack"
  • 查询
curl -i -X GET  --url http://127.0.0.1:8001/consumers/jack
  • 更新
curl -i -X PATCH  --url http://127.0.0.1:8001/consumers/jack --data "tags[]=tag1" --data "tags[]=tag2"
  • 删除
curl -i -X DELETE --url http://127.0.0.1:8001/consumers/jack
  • ALL
curl -i -X GET  --url http://127.0.0.1:8001/consumers?size=10

6. ACL

  • 创建
curl -i -X POST --url http://127.0.0.1:8001/services/example/plugins --data "name=acl" --data "config.allow=admin"
  • 非法
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'
{
  "message":"You cannot consume this service"
}
  • 授权
curl -i -X POST --url http://localhost:8001/consumers/jack/acls --data "group=admin"
  • 访问
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'









百度一下,你就知道
......................

  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/1541e339-7b8f-4a1e-8485-45b0a28b55a8

7. Basic-Auth

  • 创建
curl -i -X POST --url http://localhost:8001/services/example/plugins --data "name=basic-auth"
  • 授权
curl -i -X POST --url http://localhost:8001/consumers/jack/basic-auth --data "username=jack" --data "password=123456"
  • 非法
curl -i -X GET --url http://localhost:8000/first --header 'Host:baidu.com'
{
  "message":"Unauthorized"
}
  • 异常
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic xxxxx=" --header 'Host: baidu.com'
{
  "message":"Invalid authentication credentials"
}
  • 正常
curl -i -X GET  --url http://localhost:8000/first --header "Authorization: Basic amFjazoxMjM0NTY=" --header 'Host: baidu.com'








百度一下,你就知道
......................

  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/3d9703d5-bafb-4374-931c-a03222e3aef6

8. Key-Auth

  • 创建
curl -X POST http://localhost:8001/services/example/plugins --data "name=key-auth" --data "config.key_names=apikey"
  • 授权
curl -i -X POST --url http://localhost:8001/consumers/jack/key-auth --data 'key=123'
  • 非法
curl http://localhost:8000/first --header 'Host:baidu.com'
{
  "message":"No API key found in request"
}
  • 异常
curl http://localhost:8000/first?apikey=1231 --header 'Host:baidu.com'
{
  "message":"Invalid authentication credentials"
}
  • 正常
curl http://localhost:8000/first?apikey=123 --header 'Host:baidu.com'








百度一下,你就知道
......................

  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/2ea0a367-e17e-4e8e-9b8f-8e8b9bf49681

9. IP-Restriction

  • 创建
curl -X POST http://localhost:8001/services/example/plugins --data "name=ip-restriction" --data "config.deny=118.123.78.69"
  • 访问
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{
  "message":"Your IP address is not allowed"
}
  • 取消
curl -i -X PATCH http://localhost:8001/services/example/plugins/08fe31e8-e961-4703-9d29-a877eed7c5c1 --data "config.deny=" --data "config.allow=118.123.78.69"
  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/08fe31e8-e961-4703-9d29-a877eed7c5c1

10. Rate-Limiting

  • 创建
curl -X POST http://localhost:8001/services/example/plugins --data "name=rate-limiting" --data "config.second=2" --data "config.policy=local"
  • 访问
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{
  "message":"API rate limit exceeded"
}
  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/9172ccc6-9734-4567-a442-04b03c5d7989

11. Request-Termination

  • 创建
curl -X POST http://localhost:8001/services/example/plugins --data "name=request-termination"  --data "config.status_code=200" --data "config.message=Test !! "
  • 访问
curl -i -X GET  --url http://localhost:8000/first --header 'Host: baidu.com'
{"message":"Test ll"}
  • 删除
curl -i -X DELETE http://localhost:8001/services/example/plugins/cbf087f5-aa50-418d-a8a2-325ebb6c9109

你可能感兴趣的:(【Kong】API 操作简解)