kong 0.14到2.0X版本 API变更

Service Object

对象实体Json Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"id": "9748f662-7711-4a90-8186-dc02f10eb0f5",
"created_at": 1422386534,
"updated_at": 1422386534,
"name": "my-service",
"retries": 5,
"protocol": "http",
"host": "example.com",
"port": 80,
"path": "/some_api",
"connect_timeout": 60000,
"write_timeout": 60000,
"read_timeout": 60000,
"tags": ["user-level", "low-priority"],
"client_certificate": {"id":"4e3ad2e4-0bc4-4638-8e34-c84a417ba39b"}
}

新增

POST /services/

Request json对象参数 0.14 2.0x
The Service name name name
The protocol used to communicate with the upstream. Accepted values are: “grpc”, “grpcs”, “http”, “https”, “tcp”, “tls”. Defaults to “http”. protocol protocol
The host of the upstream server. host host
The upstream server port. Defaults to 80. port port
The path to be used in requests to the upstream server. path path
The number of retries to execute upon failure to proxy. The default is 5. retries retries
The timeout in milliseconds for establishing a connection to the upstream server. Defaults to 60000. connect_timeout connect_timeout
The timeout in milliseconds between two successive write operations for transmitting a request to the upstream server. Defaults to 60000. write_timeout write_timeout
The timeout in milliseconds between two successive read operations for transmitting a request to the upstream server. Defaults to 60000. read_timeout read_timeout
Shorthand attribute to set protocol, host, port and path at once. This attribute is write-only (the Admin API never “returns” the url). url url
An optional set of strings associated with the Service, for grouping and filtering tags
Certificate to be used as client certificate while TLS handshaking to the upstream server. With form-encoded, the notation is client_certificate.id=. With JSON, use “client_certificate”:{“id”:”“}. client_certificate

查询

GET /services/{service name or id}
GET /routes/{route id}/service
GET /services/ (offset、size可分页)

2.0x 新增接口

GET /certificates/{certificate id}/services/{service name or id}
GET /routes/{route name or id}/service
GET /plugins/{plugin id}/service

更新

PATCH /services/{name or id}
PATCH /routes/{route id}/service

2.0x 新增接口

PATCH /certificates/{certificate id}/services/{service name or id}
PATCH /routes/{route name or id}/service
PATCH /plugins/{plugin id}/service

更新或者新建

PUT /services/{name or id}

2.0x 新增接口

PUT /certificates/{certificate id}/services/{service name or id}
PUT /routes/{route name or id}/service
PUT /plugins/{plugin id}/service

删除

DELETE /services/{name or id}

2.0x 新增接口

DELETE /certificates/{certificate id}/services/{service name or id}
DELETE /routes/{route name or id}/service

Route Object

对象实体Json Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"id": "d35165e2-d03e-461a-bdeb-dad0a112abfe",
"created_at": 1422386534,
"updated_at": 1422386534,
"name": "my-route",
"protocols": ["http", "https"],
"methods": ["GET", "POST"],
"hosts": ["example.com", "foo.test"],
"paths": ["/foo", "/bar"],
"headers": {"x-another-header":["bla"], "x-my-header":["foo", "bar"]},
"https_redirect_status_code": 426,
"regex_priority": 0,
"strip_path": true,
"path_handling": "v0",
"preserve_host": false,
"tags": ["user-level", "low-priority"],
"service": {"id":"af8330d3-dbdc-48bd-b1be-55b98608834b"}
}

新增

POST /routes/

Request json对象参数 0.14 2.0x
A list of the protocols this Route should allow. When set to [“https”], HTTP requests are answered with a request to upgrade to HTTPS. Defaults to [“http”, “https”]. protocols protocols
A list of HTTP methods that match this Route. methods methods
A list of domain names that match this Route. With form-encoded, the notation is hosts[]=example.com&hosts[]=foo.test. With JSON, use an Array. hosts hosts
A list of paths that match this Route. With form-encoded, the notation is paths[]=/foo&paths[]=/bar. With JSON, use an Array. paths paths
Determines the relative order of this Route against others when evaluating regex paths. Routes with higher numbers will have their regex paths evaluated first. Defaults to 0. regex_priority regex_priority
When matching a Route via one of the paths, strip the matching prefix from the upstream request URL. Defaults to true. strip_path strip_path
When matching a Route via one of the hosts domain names, use the request Host header in the upstream request headers. By default set to false, and the upstream Host header will be that of the Service’s host. preserve_host preserve_host
The Service this Route is associated to. service service
The name of the Route. name
One or more lists of values indexed by header name that will cause this Route to match if present in the request. headers
The status code Kong responds with when all properties of a Route match except the protocol i.e. if the protocol of the request is HTTP instead of HTTPS https_redirect_status_code
Controls how the Service path, Route path and requested path are combined when sending a request to the upstream. path_handling
A list of SNIs that match this Route when using stream routing. snis
A list of IP sources of incoming connections that match this Route when using stream routing. sources
A list of IP destinations of incoming connections that match this Route when using stream routing. destinations
An optional set of strings associated with the Route, for grouping and filtering. tags

查询

GET /routes/{id}
GET /routes (offset、size可分页)
GET /services/{service name or id}/routes

2.0x 新增接口

GET /routes/{route name or id}
GET /services/{service name or id}/routes/{route name or id}
GET /plugins/{plugin id}/route

更新

PATCH /routes/{id}

2.0x 新增接口

PATCH /routes/{route name or id}
PATCH /services/{service name or id}/routes/{route name or id}
PATCH /plugins/{plugin id}/route

更新或者新建

PUT /routes/{id}

2.0x 新增接口

PUT /routes/{route name or id}
PUT /services/{service name or id}/routes/{route name or id}
PUT /plugins/{plugin id}/route

删除

DELETE /routes/{id}

2.0x 新增接口

DELETE /routes/{route name or id}
DELETE /services/{service name or id}/routes/{route name or id}

Plugin Object

对象实体Json Demo

1
2
3
4
5
6
7
8
9
10
11
12
{
"id": "ce44eef5-41ed-47f6-baab-f725cecf98c7",
"name": "rate-limiting",
"created_at": 1422386534,
"route": null,
"service": null,
"consumer": null,
"config": {"hour":500, "minute":20},
"protocols": ["http", "https"],
"enabled": true,
"tags": ["user-level", "low-priority"]
}

新增

POST /plugins/

Request json对象参数 0.14 2.0x
The name of the Plugin that’s going to be added. Currently the Plugin must be installed in every Kong instance separately. name name
The unique identifier of the consumer that overrides the existing settings for this specific consumer on incoming requests. consumer_id consumer
The unique identifier of the service that overrides the existing settings for this specific service on incoming requests. service_id service
The unique identifier of the route that overrides the existing settings for this specific route on incoming requests. route_id route
The configuration properties for the Plugin which can be found on the plugins documentation page in the Kong Hub. config config
Whether the plugin is applied. Default: true. enabled enabled
. For example, plugins that only work in stream mode will only support “tcp” and “tls”. Defaults to [“grpc”, “grpcs”, “http”, “https”]. protocols
An optional set of strings associated with the Plugin, for grouping and filtering tags

2.0x 新增接口

POST /routes/{route id}/plugins
POST /services/{service id}/plugins
POST /consumers/{consumer id}/plugins

查询

GET /plugins/{id}
GET /plugins/
GET /plugins/enabled
GET /plugins/schema/{plugin name}

2.0x 新增接口

GET /routes/{route id}/plugins
GET /services/{service id}/plugins
GET /consumers/{consumer id}/plugins

GET /routes/{route name or id}/plugins/{plugin id}
GET /services/{service name or id}/plugins/{plugin id}
GET /consumers/{consumer username or id}/plugins/{plugin id}

更新

PATCH /plugins/{plugin id}

2.0x 新增接口

PATCH /routes/{route name or id}/plugins/{plugin id}
PATCH /services/{service name or id}/plugins/{plugin id}
PATCH /consumers/{consumer username or id}/plugins/{plugin id}

更新或者新建

PUT /plugins/ 在2.0 修改为 PUT /plugins/{plugin id}

2.0x 新增接口

PUT /routes/{route name or id}/plugins/{plugin id}
PUT /services/{service name or id}/plugins/{plugin id}
PUT /consumers/{consumer username or id}/plugins/{plugin id}

删除

DELETE /plugins/{plugin id}

2.0x 新增接口

DELETE /routes/{route name or id}/plugins/{plugin id}
DELETE /services/{service name or id}/plugins/{plugin id}
DELETE /consumers/{consumer username or id}/plugins/{plugin id}

Upstream Objects

对象实体Json Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
"id": "58c8ccbb-eafb-4566-991f-2ed4f678fa70",
"created_at": 1422386534,
"name": "my-upstream",
"algorithm": "round-robin",
"hash_on": "none",
"hash_fallback": "none",
"hash_on_cookie_path": "/",
"slots": 10000,
"healthchecks": {
"active": {
"https_verify_certificate": true,
"unhealthy": {
"http_statuses": [429, 404, 500, 501, 502, 503, 504, 505],
"tcp_failures": 0,
"timeouts": 0,
"http_failures": 0,
"interval": 0
},
"http_path": "/",
"timeout": 1,
"healthy": {
"http_statuses": [200, 302],
"interval": 0,
"successes": 0
},
"https_sni": "example.com",
"concurrency": 10,
"type": "http"
},
"passive": {
"unhealthy": {
"http_failures": 0,
"http_statuses": [429, 500, 503],
"tcp_failures": 0,
"timeouts": 0
},
"type": "http",
"healthy": {
"successes": 0,
"http_statuses": [200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308]
}
},
"threshold": 0
},
"tags": ["user-level", "low-priority"],
"host_header": "example.com"
}

新增

POST /upstreams/

Request json对象参数 0.14 2.0x
This is a hostname, which must be equal to the host of a Service. name name
The number of slots in the loadbalancer algorithm (10-65536, defaults to 1000). slots slots
What to use as hashing input: none, consumer, ip, header, or cookie (defaults to none resulting in a weighted-round-robin scheme). hash_on hash_on
What to use as hashing input if the primary hash_on does not return a hash hash_fallback hash_fallback
The header name to take the value from as hash input (only required when hash_on is set to header). hash_on_header hash_on_header
The header name to take the value from as hash input (only required when hash_fallback is set to header). hash_fallback_header hash_fallback_header
The cookie name to take the value from as hash input (only required when hash_on or hash_fallback is set to cookie) hash_on_cookie hash_on_cookie
The cookie path to set in the response headers hash_on_cookie_path hash_on_cookie_path
Socket timeout for active health checks (in seconds). Defaults to 1. healthchecks.active.timeout healthchecks.active.timeout
Number of targets to check concurrently in active health checks. Defaults to 10 healthchecks.active.concurrency healthchecks.active.concurrency
Path to use in GET HTTP request to run as a probe on active health checks. healthchecks.active.http_path healthchecks.active.http_path
Interval between active health checks for healthy targets (in seconds). A value of zero indicates that active probes for healthy targets should not be performed. Defaults to 0 healthchecks.active.healthy.interval healthchecks.active.healthy.interval
An array of HTTP statuses to consider a success, indicating healthiness, when returned by a probe in active health checks. Defaults to 0 healthchecks.active.healthy.http_statuses healthchecks.active.healthy.http_statuses
Number of successes in active probes (as defined by healthchecks.active.healthy.http_statuses) to consider a target healthy. Defaults to 0 healthchecks.active.healthy.successes healthchecks.active.healthy.successes
An optional set of strings associated with the Upstream, for grouping and filtering. tags
The hostname to be used as Host header when proxying requests through Kong. host_header

查询

GET /upstreams/{name or id}
GET /upstreams/ (offset、size可分页)

GET /upstreams/{name or id}/health/

2.0x 新增接口

GET /targets/{target host:port or id}/upstream

更新

PATCH /upstreams/{name or id}

2.0x 新增接口

PATCH /targets/{target host:port or id}/upstream

更新或者新建

PUT /upstreams/ 在2.0 修改为 PUT /upstreams/{upstream name or id}

2.0x 新增接口

PUT /targets/{target host:port or id}/upstream

删除

DELETE /upstreams/{name or id}

2.0x 新增接口

DELETE /targets/{target host:port or id}/upstream

参考

0.14
2.0x