## 7\. Plugins *地址*:/plugins *说明*:插件,插件作用域:global、service、route,优先级:route>service>global ### 7.1 请求方法 | 序号 | NAME | 请求URI | 请求body | 说明 | | --- | --- | --- | --- | --- | | 1 | POST | /plugins | {...} | 新增全局插件 | | 2 | ~ | /routes/{route id}/plugins | ~ | 新增route范围内的插件 | | 3 | ~ | /services/{service id}/plugins | ~ | 新增service范围内的插件 | | 4 | ~ | /consumers/{consumer id}/plugins | ~ | 新增consumer权限下的插件 | | 5 | GET | /plugins | | 查询插件列表 | | 6 | ~ | /routes/{route id}/plugins | | 查询路由下的所有插件 | | 7 | ~ | /services/{service id}/plugins | | 查询sercie下的所有插件 | | 8 | ~ | /consumers/{consumer id}/plugins | | 查询consumer下的所有插件 | | 9 | GET | /plugins/{plugin id} | | 获取插件信息 | | 10 | PATCH | /plugins/{plugin id} | | 更新插件信息 | | 11 | PUT | /plugins/{plugin id} | | 新增/更新插件信息 | | 12 | DELETE | /plugins/{plugin id} | | 删除插件 | | 13 | GET | /plugins/schema/{plugin name} | 插件名称 | 获取plugin的schema | | ***14*** | ***GET*** | ***/plugins/enabled*** | \*\*\*\*\*\* | ***v1.3.x版本以上*** | ### 7.2 body 请求参数 | 序号 | 参数名 | 可选 | 默认值 | 说明 | 示例 | | --- | --- | --- | --- | --- | --- | | 1 | name | 必选 | | 插件名称 | basic-auth | | 2 | route | 可选 | | 路由ID | "route":{"id":""} | | 3 | service | 可选 | | serviceID | "service":{"id":""} | | 4 | consumer | | | consumerID | "consumer":{"id":""} | | 5 | config | 可选 | {} | | | | 6 | run\_on | 必选 | first | | | | 7 | protocols | | \["http","https"\] | `"http"`,`"https"`,`"tcp"`, and`"tls"` | | | 8 | enabled | 可选 | true | 是否启用 | true or false | | 9 | tags | 可选 | | 标签 | | ### 7.3 数据样例 body 请求参数 ``` { "id": "ec1a1f6f-2aa4-4e58-93ff-b56368f19b27", "name": "rate-limiting", "created_at": 1422386534, "route": null, "service": null, "consumer": null, "config": {"hour":500, "minute":20}, "run_on": "first", "protocols": ["http", "https"], "enabled": true, "tags": ["user-level", "low-priority"] } ``` 插件列表 ``` { "data": [{ "id": "a4407883-c166-43fd-80ca-3ca035b0cdb7", "name": "rate-limiting", "created_at": 1422386534, "route": null, "service": null, "consumer": null, "config": {"hour":500, "minute":20}, "run_on": "first", "protocols": ["http", "https"], "enabled": true, "tags": ["user-level", "low-priority"] }, { "id": "01c23299-839c-49a5-a6d5-8864c09184af", "name": "rate-limiting", "created_at": 1422386534, "route": null, "service": null, "consumer": null, "config": {"hour":500, "minute":20}, "run_on": "first", "protocols": ["tcp", "tls"], "enabled": true, "tags": ["admin", "high-priority", "critical"] }], "next": "http://localhost:8001/plugins?offset=6378122c-a0a1-438d-a5c6-efabae9fb969" } ``` 插件schema ``` { "fields": { "hide_credentials": { "default": false, "type": "boolean" }, "key_names": { "default": "function", "required": true, "type": "array" } } } ```