You may want to assign an ID for your API requests so that you can identify the request from external systems like querying the access log or the trace.
This guide will teach you how to add ID for your API requests with the help of the Request ID plugin.
Prepare the Environment
Deploy Apache APISIX
Please refer to How to Deploy Apache APISIX to learn how to deploy Apache APISIX and connect it to API7 Cloud. In this guide, we'll deploy an Apache APISIX instance on Docker.
Create Service and Route
We'll create a service with the following details in this guide.
- The service name is
- The path prefix is
- The HTTP Host is
- The upstream URL is
Besides, we'll create a route inside the
- The route name is
- The path is
/anything(prefix match), and strip the path prefix.
- It accepts all HTTP methods.
If you don't know how to configure a service and route, please refer to the Getting Started guides first
Add Request ID Plugin
Now let's add the Request ID plugin to the
API7 Cloud will add an UUID for each request in this Service. We also include the ID in the response header.
Now let's send a request to the
curl http://127.0.0.1:9080/v1/anything -H 'Host: request-id.httpbin.org' -i
HTTP/1.1 200 OK
Date: Wed, 17 Aug 2022 08:16:10 GMT
"origin": "172.17.0.1, 184.108.40.206",
As you can see from the response body, Apache APISIX takes the
My-Request-ID header when forwarding the request to the backend.
Also, since we enable the
Include in Response option, the
My-Request-ID header is shown in the response header.
Apache APISIX won't overwrite the request ID header if it already exists. Try to send another request with the header