Skip to main content

Version: 2.13.2304

Request Rewrite

Prepare environment

Please refer to API7 EE Introduction to complete the environment preparation.

Create route with proxy rewrite

Create an API, this time we don't need to open the plugin.

20230323152749

Set a special uri that is not /anything.

20230323152801

Next we set two things,

  • Rewrites path by replacing prefix, rewriting /otherapi to /anything.
  • Adds a header and removes a client's header.
    • X-Test = JustForPoC will be added
    • X-Delete form client will be deleted

20230323152814

Test

Request to /otherapi and rewrite

curl 127.0.0.1/otherapi -i -H "Host: example.com"
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 423
Connection: keep-alive
Date: Mon, 13 Mar 2023 05:50:01 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/2.13.2304

{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Host": "example.com",
"User-Agent": "curl/7.81.0",
"X-Amzn-Trace-Id": "Root=1-640eb989-36c729174cc2d500586bb7c5",
"X-Forwarded-Host": "example.com",
"X-Test": "JustForPoC" # X-Test header added
},
"json": null,
"method": "GET",
"origin": "172.17.0.1, 146.190.80.65",
"url": "http://example.com/anything" # /otherapi uri rewrited
}

Request and delete client's header

curl 127.0.0.1/otherapi -i -H "Host: example.com" -H "X-Delete: WillBeDeleted"
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 423
Connection: keep-alive
Date: Mon, 13 Mar 2023 05:52:18 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/2.13.2304

{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": { # X-Delete header deleted
"Accept": "*/*",
"Host": "example.com",
"User-Agent": "curl/7.81.0",
"X-Amzn-Trace-Id": "Root=1-640eba12-193711166c97a91b01ba30b9",
"X-Forwarded-Host": "example.com",
"X-Test": "JustForPoC"
},
"json": null,
"method": "GET",
"origin": "172.17.0.1, 146.190.80.65",
"url": "http://example.com/anything"
}

API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation