## 12\. Targets *地址*:/targets *说明*:upstream下服务器的抽象实体,对应nginx配置的server,可参考[](../6.1kong简介.md)[6.1 Kong简介](../6.1kong简介.md) ### 12.1 请求方法 | 序号 | NAME | 请求URI | 请求body | 说明 | | --- | --- | --- | --- | --- | | 1 | POST | /upstreams/{upstream host:port or id}/targets | {...} | 新增targets | | 2 | GET | /upstreams/{upstream host:port or id}/targets | upstream name or id | 查询targets列表 | | 3 | DELETE | /upstreams/{upstream name or id}/targets/{host:port or id} | upstream name or id | | | target name or id | 删除target | | | | | 4 | POST | /upstreams/{upstream name or id}/targets/{target or id}/healthy | upstream name or id | | | target name or id | 设置target为healthy | | | | | 5 | POST | /upstreams/{upstream name or id}/targets/{target or id}/unhealthy | upstream name or id target name or id | 设置target为unhealthy | | 6 | GET | /upstreams/{name or id}/targets/all/ | upstream name or id | 查询upstream下所有targets | ### 12.2 body 请求参数 | 序号 | 参数名 | 可选 | 默认值 | 说明 | 示例 | | --- | --- | --- | --- | --- | --- | | 1 | target | 必选 | | (ip or hostname) 和port | 127.0.0.1:8080 | | 2 | weight | 可选 | 100 | 权重(0-1000) | 100 | | 3 | tags | 可选 | | 标签 | | ### 12.3 数据样例 body 请求参数 ``` { "id": "a3ad71a8-6685-4b03-a101-980a953544f6", "created_at": 1422386534, "upstream": {"id":"b87eb55d-69a1-41d2-8653-8d706eecefc0"}, "target": "example.com:8000", "weight": 100, "tags": ["user-level", "low-priority"] } ``` targets列表 ``` { "total": 2, "data": [ { "created_at": 1485524883980, "id": "18c0ad90-f942-4098-88db-bbee3e43b27f", "target": "127.0.0.1:20000", "upstream_id": "07131005-ba30-4204-a29f-0927d53257b4", "weight": 100 }, { "created_at": 1485524914883, "id": "6c6f34eb-e6c3-4c1f-ac58-4060e5bca890", "target": "127.0.0.1:20002", "upstream_id": "07131005-ba30-4204-a29f-0927d53257b4", "weight": 200 } ] } ```