2020-08-12 23:09:39 +08:00
|
|
|
<!--
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
-->
|
|
|
|
|
|
|
|
# Summary
|
2021-01-03 11:26:40 +08:00
|
|
|
|
2020-08-12 23:09:39 +08:00
|
|
|
- [**Name**](#name)
|
|
|
|
- [**Attributes**](#attributes)
|
|
|
|
- [**How To Enable**](#how-to-enable)
|
|
|
|
- [**Test Plugin**](#test-plugin)
|
|
|
|
- [**Disable Plugin**](#disable-plugin)
|
|
|
|
|
|
|
|
## Name
|
|
|
|
|
|
|
|
`request-id` plugin adds a unique ID (UUID) to each request proxied through APISIX. This plugin can be used to track an
|
|
|
|
API request. The plugin will not add a request id if the `header_name` is already present in the request.
|
|
|
|
|
|
|
|
## Attributes
|
|
|
|
|
2020-09-23 08:11:27 +08:00
|
|
|
| Name | Type | Requirement | Default | Valid | Description |
|
|
|
|
| ------------------- | ------- | ----------- | -------------- | ----- | -------------------------------------------------------------- |
|
|
|
|
| header_name | string | optional | "X-Request-Id" | | Request ID header name |
|
|
|
|
| include_in_response | boolean | optional | false | | Option to include the unique request ID in the response header |
|
2020-08-12 23:09:39 +08:00
|
|
|
|
|
|
|
## How To Enable
|
|
|
|
|
|
|
|
Create a route and enable the request-id plugin on the route:
|
|
|
|
|
|
|
|
```shell
|
2020-11-28 19:05:14 +08:00
|
|
|
curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
2020-08-12 23:09:39 +08:00
|
|
|
{
|
|
|
|
"uri": "/get",
|
|
|
|
"plugins": {
|
|
|
|
"request-id": {
|
|
|
|
"include_in_response": true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
2020-08-26 09:37:53 +08:00
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:8080": 1
|
|
|
|
}
|
2020-08-12 23:09:39 +08:00
|
|
|
}
|
2021-01-20 09:02:01 +08:00
|
|
|
}'
|
2020-08-12 23:09:39 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Test Plugin
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ curl -i http://127.0.0.1:9080/hello
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
```
|
|
|
|
|
|
|
|
## Disable Plugin
|
|
|
|
|
2020-08-23 11:17:18 +08:00
|
|
|
Remove the corresponding json configuration in the plugin configuration to disable the `request-id`.
|
2020-08-12 23:09:39 +08:00
|
|
|
APISIX plugins are hot-reloaded, therefore no need to restart APISIX.
|
|
|
|
|
|
|
|
```shell
|
2020-11-28 19:05:14 +08:00
|
|
|
curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
2020-08-12 23:09:39 +08:00
|
|
|
{
|
|
|
|
"uri": "/get",
|
|
|
|
"plugins": {
|
|
|
|
},
|
|
|
|
"upstream": {
|
2020-08-26 09:37:53 +08:00
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:8080": 1
|
|
|
|
}
|
2020-08-12 23:09:39 +08:00
|
|
|
}
|
2021-01-20 09:02:01 +08:00
|
|
|
}'
|
2020-08-12 23:09:39 +08:00
|
|
|
```
|