KONG API网关管理接口说明_第1页
KONG API网关管理接口说明_第2页
KONG API网关管理接口说明_第3页
KONG API网关管理接口说明_第4页
KONG API网关管理接口说明_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、KONG API网关管理接口说明一、KONG网关的管理接口地址http:/localhost:8001/二、API管理接口1、新增API服务端点/apis/请求方法POST请求参数name - API 名称uris - 指向API的URI地址upstream_url - 调用的原始服务地址返回结果HTTP 201 Created操作示例rootCentOS # curl -i -X POST -url http:/localhost:8001/apis/ -d name=test -d upstream_url=3:3001/ -d uris=/api/te

2、stHTTP/1.1 201 CreatedDate: Thu, 28 Sep 2017 02:19:42 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,strip_uri:true,id:fa5c8c96-878b-4ba2-bd08-f2128b5fa760,name:test,http_if_terminated:fal

3、se,preserve_host:false,upstream_url:3:3001/,uris:/api/test,upstream_connect_timeout:60000,upstream_send_timeout:60000,upstream_read_timeout:60000,retries:5,https_only:false2、获取单个API信息服务端点/apis/name or id 请求方法GET请求参数返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET -url http:/localhost

4、:8001/apis/testHTTP/1.1 200 OKDate: Thu, 28 Sep 2017 02:28:04 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,strip_uri:true,id:fa5c8c96-878b-4ba2-bd08-f2128b5fa760,name:test,http_if_termin

5、ated:false,https_only:false,upstream_url:3:3001/,uris:/api/test,preserve_host:false,upstream_connect_timeout:60000,upstream_read_timeout:60000,upstream_send_timeout:60000,retries:5rootCentOS # curl -i -X GET -url http:/localhost:8001/apis/fa5c8c96-878b-4ba2-bd08-f2128b5fa760HTTP/1.

6、1 200 OKDate: Thu, 28 Sep 2017 02:29:00 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,strip_uri:true,id:fa5c8c96-878b-4ba2-bd08-f2128b5fa760,name:test,http_if_terminated:false,https_only:

7、false,upstream_url:3:3001/,uris:/api/test,preserve_host:false,upstream_connect_timeout:60000,upstream_read_timeout:60000,upstream_send_timeout:60000,retries:53、获取API列表服务端点/apis/请求方法GET请求参数返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET -url http:/localhost:8001/apis/HTTP/1.1 200 OKD

8、ate: Thu, 28 Sep 2017 02:34:57 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0total:1,data:created_at:00,strip_uri:true,id:fa5c8c96-878b-4ba2-bd08-f2128b5fa760,name:test,http_if_terminated:false,https_o

9、nly:false,upstream_url:3:3001/,uris:/api/test,preserve_host:false,upstream_connect_timeout:60000,upstream_read_timeout:60000,upstream_send_timeout:60000,retries:54、更新API服务端点/apis/name or id 请求方法PATCH请求参数name - API 名称uris - 指向API的URI地址upstream_url - 调用的原始服务地址返回结果HTTP 200 OK操作示例rootC

10、entOS # curl -i -X PATCH -url http:/localhost:8001/apis/test -d name=test1HTTP/1.1 200 OKDate: Thu, 28 Sep 2017 02:48:29 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,strip_uri:true,id:fa

11、5c8c96-878b-4ba2-bd08-f2128b5fa760,name:test1,http_if_terminated:false,preserve_host:false,upstream_url:3:3001/,uris:/api/test,upstream_connect_timeout:60000,upstream_send_timeout:60000,upstream_read_timeout:60000,retries:5,https_only:false5、删除API服务端点/apis/name or id 请求方法DELETE请求参数

12、返回结果HTTP 204 No Content操作示例rootCentOS # curl -i -X DELETE http:/localhost:8001/apis/testHTTP/1.1 204 No ContentDate: Thu, 28 Sep 2017 03:04:20 GMTConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0rootCentOS # curl -i -X GET -url http:/localhost:8001/apis/HTTP/1.1 200 OKDate: Thu

13、, 28 Sep 2017 03:04:34 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0total:0,data:6、表定义参考(PostgreSQL)字段名类型备注iduuid非空nametextupstream_urltextpreserve_hostboolean非空created_attimestamp without time zone默认

14、 timezone(utc:text, (now:text):timestamp(0) with time zone)retriessmallint默认 5https_onlybooleanhttp_if_terminatedbooleanhoststexturistextmethodstextstrip_uribooleanupstream_connect_timeoutintegerupstream_send_timeoutintegerupstream_read_timeoutinteger索引:apis_pkey PRIMARY KEY, btree (id)apis_name_key

15、 UNIQUE CONSTRAINT, btree (name)apis_name_idx btree (name)7、产品文档参考/docs/0.11.x/admin-api/#api-object三、用户管理接口1、新增用户服务端点/consumers/请求方法POST请求参数username - 用户名custom_id - 用户ID返回结果HTTP 201 Created操作示例rootCentOS # curl -i -X POST http:/localhost:8001/consumers/ -d username=test -d custom

16、_id=testHTTP/1.1 201 CreatedDate: Thu, 28 Sep 2017 10:29:30 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0custom_id:test,created_at:00,username:test,id:7ea0c46d-5f50-462a-a9ce-fbfefc309cef2、获取单个用户信息服务端

17、点/consumers/username or id 请求方法GET请求参数返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET http:/localhost:8001/consumers/testHTTP/1.1 200 OKDate: Thu, 28 Sep 2017 11:02:46 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server:

18、 kong/0.11.0custom_id:test,created_at:00,username:test,id:7ea0c46d-5f50-462a-a9ce-fbfefc309cefrootCentOS # curl -i -X GET http:/localhost:8001/consumers/7ea0c46d-5f50-462a-a9ce-fbfefc309cefHTTP/1.1 200 OKDate: Thu, 28 Sep 2017 11:03:42 GMTContent-Type: application/json; charset=utf-8Transfer-Encodin

19、g: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0custom_id:test,created_at:00,username:test,id:7ea0c46d-5f50-462a-a9ce-fbfefc309cef3、获取用户列表服务端点/consumers/请求方法GET请求参数返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET http:/localhost:8001/consumers/HTTP/1.1 200 OKDate: Thu,

20、 28 Sep 2017 11:22:41 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0total:1,data:custom_id:test,created_at:00,username:test,id:7ea0c46d-5f50-462a-a9ce-fbfefc309cef4、更新用户服务端点/consumers/username or id请求方

21、法PATCH请求参数username - 用户名称custom_id - 用户ID返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X PATCH -url http:/localhost:8001/consumers/test -d username=test1 -d custom_id=test1HTTP/1.1 200 OKDate: Thu, 28 Sep 2017 11:29:44 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection:

22、keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0custom_id:test1,created_at:00,username:test1,id:7ea0c46d-5f50-462a-a9ce-fbfefc309cef5、删除用户服务端点/consumers/username or id请求方法DELETE请求参数返回结果HTTP 204 No Content操作示例rootCentOS # curl -i -X DELETE -url http:/localhost:8001/consumers/test1HTTP/1.1

23、204 No ContentDate: Thu, 28 Sep 2017 11:37:46 GMTConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.06、表定义参考(PostgreSQL)字段名类型备注iduuid非空customer_idtextusernametextcreated_attimestamp without time zone默认 timezone(utc:text, (now:text):timestamp(0) with time zone)索引:consumers_pkey PRI

24、MARY KEY, btree (id)consumers_custom_id_key UNIQUE CONSTRAINT, btree (custom_id)consumers_username_key UNIQUE CONSTRAINT, btree (username)custom_id_idx btree (custom_id)username_idx btree (lower(username)7、产品文档参考/docs/0.11.x/admin-api/#consumer-object四、插件管理接口1、获取已安装的插件服务端点/plugins/

25、enabled请求方法GET请求参数返回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET http:/localhost:8001/plugins/enabledHTTP/1.1 200 OKDate: Fri, 29 Sep 2017 03:10:06 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0enabled

26、_plugins:response-transformer,correlation-id,statsd,jwt,cors,basic-auth,key-auth,ldap-auth,oauth2,http-log,ip-restriction,hmac-auth,request-size-limiting,datadog,tcp-log,request-transformer,file-log,acl,bot-detection,loggly,galileo,syslog,udp-log,response-ratelimiting,aws-lambda,runscope,rate-limiti

27、ng,request-termination2、新增插件服务端点/plugins/请求方法POST请求参数name - 已安装插件的名称perty - 插件的配置参数返回结果HTTP 201 Created操作示例rootCentOS # curl -i -X POST http:/localhost:8001/plugins -d name=key-auth -d config.hide_credentials=trueHTTP/1.1 201 CreatedDate: Wed, 27 Sep 2017 08:24:59 GMTContent-Type: applicat

28、ion/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,config:key_in_body:false,anonymous:,key_names:apikey,hide_credentials:true,id:ec-305d-477f-bd66-3c8f4a8e32dc,enabled:true,name:key-auth3、列出插件服务端点/plugins/请求方法GET请求参数返

29、回结果HTTP 200 OK操作示例rootCentOS # curl -i -X GET http:/localhost:8001/plugins/HTTP/1.1 200 OKDate: Fri, 29 Sep 2017 05:12:41 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0total:2,data:created_at:00,config

30、:http_endpoint::3000/,timeout:10000,method:POST,keepalive:60000,content_type:application/json,id:370f0b39-9e90-4d8f-8dba-c4ee648a1435,enabled:true,name:http-log,created_at:00,config:key_in_body:false,anonymous:,key_names:apikey,hide_credentials:true,id:ec-305d-477f-bd66-3c8f4a8e32d

31、c,enabled:true,name:key-auth4、删除插件服务端点/plugins/plugin id 请求方法DELETE请求参数返回结果HTTP 204 No Content操作示例rootCentOS # curl -i -X DELETE http:/localhost:8001/plugins/ec-305d-477f-bd66-3c8f4a8e32dcHTTP/1.1 204 No ContentDate: Fri, 29 Sep 2017 05:31:34 GMTConnection: keep-aliveAccess-Control-Allow-Origin: *Se

32、rver: kong/0.11.05、表定义参考(PostgreSQL)字段名类型备注iduuid非空nametext非空api_iduuidcustomer_iduuidconfigjson非空enableboolean非空created_attimestamp without time zone默认 timezone(utc:text, (now:text):timestamp(0) with time zone)索引:plugins_pkey PRIMARY KEY, btree (id, name)plugins_id_key UNIQUE CONSTRAINT, btree (id)

33、plugins_api_idx btree (api_id)plugins_consumer_idx btree (consumer_id)plugins_name_idx btree (name)6、产品文档参考/docs/0.11.x/admin-api/#plugin-object五、数据服务总线项目中插件的使用1、插件Key Authentication说明 插件Key Authentication用于增加对API访问的控制,启用该插件后,使用者需要将个人的API KEY放入访问链接中才能调用网关上发布的API。启用该插件后,需要先增加用户,再给用户

34、生成API KEY。 用于插件管理接口的主要参数参数名含义值name插件名称key-authconfig.hide_credentials是否向真实 API Server隐藏apikeytrue为指定用户生成API KEY的管理接口服务端点/consumers/consumer/key-auth请求方法POST请求参数key - 设置指定值为API KEY,不指定的由系统生成API KEY返回结果HTTP 201 Created操作示例rootCentOS # curl -i -X POST http:/localhost:8001/consumers/test/key-auth -d HTT

35、P/1.1 201 CreatedDate: Fri, 29 Sep 2017 06:50:32 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0id:bd36dc64-2ab4-45a7-bab2-fc8aa0cf09ca,created_at:00,key:FCcxpOWdwUIKgNN8XfOT1UlDdAkgA14G,consumer_id:8ae

36、945bc-b007-43da-8bef-5ff67a08ca13文档参考/plugins/key-authentication/2、插件HTTP Log说明 插件HTTP Log用于将网关上请求和回复的日志发送到HTTP Server。 用于管理接口的主要参数参数名含义值name插件名称http-logconfig.http_endpoint数据发送至的HTTP端点文档参考/plugins/http-log/3、简单示例API代码:var http = require(http); http.createServer(f

37、unction(request, response) response.writeHead(200, Content-Type: text/plain); response.write(Hello World); response.end();).listen(3001);HTTP Server代码:var http = require(http);http.createServer(function (req, res) var body = ; req.on(data, function (chunk) body += chunk; ); req.on(end, function () v

38、ar obj = JSON.parse(body);console.log(obj);console.log(关键信息);console.log(client_ip: + obj.client_ip);if (!(typeof(obj.consumer) = undefined) console.log(consumer.custom_id: + obj.consumer.custom_id); console.log(consumer.username: + obj.consumer.username); console.log(consumer.id: + obj.consumer.id)

39、;console.log(api.id: + obj.api.id);console.log(: + );console.log(api.upstream_url: + obj.api.upstream_url);console.log(latencies.request: + obj.latencies.request);console.log(latencies.kong: + xy);console.log(xy: + xy); res.writeHead

40、(200); res.end(); );).listen(3000);在node.js环境中,分别执行以上代码段。网关操作:配置HTTP LogrootCentOS # curl -i -X POST http:/localhost:8001/plugins -d name=http-log -d config.http_endpoint=:3000/HTTP/1.1 201 CreatedDate: Fri, 29 Sep 2017 06:23:52 GMTContent-Type: application/json; charset=utf-8Trans

41、fer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,config:http_endpoint::3000/,timeout:10000,method:POST,keepalive:60000,content_type:application/json,id:cc-cc37-4893-9d8b-8749c6b41efd,enabled:true,name:http-log配置APIrootCentOS

42、# curl -i -X POST -url http:/localhost:8001/apis/ -d name=test -d upstream_url=:3001/ -d uris=/api/testHTTP/1.1 201 CreatedDate: Fri, 29 Sep 2017 06:25:04 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *S

43、erver: kong/0.11.0created_at:00,strip_uri:true,id:20eba31d-1441-4f62-b1e9-b033a56fcc75,name:test,http_if_terminated:false,preserve_host:false,upstream_url::3001/,uris:/api/test,upstream_connect_timeout:60000,upstream_send_timeout:60000,upstream_read_timeout:60000,retries:5,https_on

44、ly:false浏览器操作:在浏览器中,输入网关的URI访问发布的API,结果如下:29:8010/api/testHTTP Log的信息: api: created_at: 00, strip_uri: true, id: 8445b269-dd0d-40eb-9982-e856, name: test, http_if_terminated: false, https_only: false, upstream_url: :3001/, uris: /api/test , preserve_host: false, u

45、pstream_connect_timeout: 60000, upstream_read_timeout: 60000, upstream_send_timeout: 60000, retries: 5 , request: querystring: , size: 477, uri: /api/test, request_uri: 29:8010/api/test, method: GET, headers: host: 29:8010, connection: keep-alive, upgrade-insecure-reque

46、sts: 1, cache-control: max-age=0, cookie: config.url=%22http%3A%2F%2F29%3A8001%22, accept-encoding: gzip, deflate, user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36, accept-language: zh-CN,zh;q=0.8, accept: text/html

47、,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 , client_ip: , latencies: request: 4, kong: 0, proxy: 4 , response: headers: content-type: text/plain; charset=UTF-8, date: Fri, 29 Sep 2017 06:37:24 GMT, via: kong/0.11.0, connection: close, x-kong-proxy-latenc

48、y: 0, x-kong-upstream-latency: 4, transfer-encoding: chunked , status: 200, size: 241 , tries: balancer_latency: 0, port: 3001, ip: , started_at: 20 关键信息client_ip: api.id: 8445: testapi.upstream_url: :3001/latencies.request:

49、4latencies.kong: 4xy: 4网关操作:配置Key AuthenticationrootCentOS # curl -i -X POST http:/localhost:8001/plugins -d name=key-auth -d config.hide_credentials=trueHTTP/1.1 201 CreatedDate: Fri, 29 Sep 2017 06:43:24 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnect

50、ion: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0created_at:00,config:key_in_body:false,anonymous:,key_names:apikey,hide_credentials:true,id:2dc9b841-d30d-4aee-ae9d-34a,enabled:true,name:key-auth配置ConsumerrootCentOS # curl -i -X POST http:/localhost:8001/consumers/ -d username=test -d custom_id=testHTTP/1.1 201 CreatedDate: Fri, 29 Sep 2017 06:44:36 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-Control-Allow-Origin: *Server: kong/0.11.0custom_id:test,created_at

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论