service 添加
请求地址 /services
请求方式 POST
请求主体
- name (可选) 服务名称
- protocol 该协议用于upstream通信。可以是http(默认)或者 https
- host upstream 服务器主机
- port 服务器端口,默认80
- path(可选) 在向upstream服务器请求中使用的路径。默认为空
- retries(可选) 在代理失败的情况下执行重试次数,默认为5
- connect_timeout(可选) 建立Upstream服务器连接的超时间默认为60000
- write_timeout(可选) 将请求发送到Upstream服务器的两个连接之间写操作超时时间,默认60000
- read-time(可选) 将请求发送到Upstream服务器的两个连接之间读操作超时时间,默认60000
- url(简写属性) 将协议、主机、端口和路径设置成简单的属性。这个属性是只写的(管理API从不返回url)
例:
$ curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=example-service' \
--data 'url=http://mockbin.org'
应答信息:
HTTP/1.1 201 Created
Date: Mon, 20 Apr 2020 02:21:26 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/2.0.3
Content-Length: 296
X-Kong-Admin-Latency: 16
{
"host":"mockbin.org",
"created_at":1587349286,
"connect_timeout":60000,
"id":"7bed6af7-c6d0-4228-a2b0-e0103d17aa0a",
"protocol":"http",
"name":"example-service",
"read_timeout":60000,
"port":80,
"path":null,
"updated_at":1587349286,
"retries":5,
"write_timeout":60000,
"tags":null,
"client_certificate":null
}
service列表
请求地址 /services
请求方式 GET
参数
- Offset 分页游标
- size(可选默认100 最大1000) 每页显示的条数
例
curl -X GET --url http://localhost:8001/services
{
"next":null,
"data":[
{
"host":"mockbin.org",
"created_at":1587349286,
"connect_timeout":60000,
"id":"7bed6af7-c6d0-4228-a2b0-e0103d17aa0a",
"protocol":"http",
"name":"example-service",
"read_timeout":60000,
"port":80,
"path":null,
"updated_at":1587349286,
"retries":5,
"write_timeout":60000,
"tags":null,
"client_certificate":null
}]
}
查找service
请求地址 /services/{name or id }
请求方式 GET
参数
- (name or id ) 必填 检索的唯一标示或者服务名称
例
curl -X GET --url http://localhost:8001/services/example-service
{
"next":null,
"data":[
{
"host":"mockbin.org",
"created_at":1587349286,
"connect_timeout":60000,
"id":"7bed6af7-c6d0-4228-a2b0-e0103d17aa0a",
"protocol":"http",
"name":"example-service",
"read_timeout":60000,
"port":80,
"path":null,
"updated_at":1587349286,
"retries":5,
"write_timeout":60000,
"tags":null,
"client_certificate":null
}]
}
更新service
请求地址 /services/{name or id}
请求方式 PATCH
参数
- (Name or id )必填_ 要更新服务的id或者name
例
curl -i -X PATCH \
--url http://localhost:8001/services/example-service2 \
--data 'url=http://mockbin3.org'
HTTP/1.1 200 OK
Date: Mon, 20 Apr 2020 07:48:55 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/2.0.3
Content-Length: 298
X-Kong-Admin-Latency: 32
{
"host":"mockbin3.org",
"created_at":1587368863,
"connect_timeout":60000,
"id":"4a156447-a99f-4e48-853d-a23060d45a8a",
"protocol":"http",
"name":"example-service2",
"read_timeout":60000,
"port":80,
"path":null,
"updated_at":1587368935,
"retries":5,
"write_timeout":60000,
"tags":null,
"client_certificate":null
}
删除service
请求地址 /services/{name or id}
请求方式 DELETE
参数
- (Name or id )必填 要删除的服务的那么或者id
例
curl -X DELETE \
--url http://localhost:8001/services/example-service2