echo

Description

The echo Plugin is to help users understand how they can develop an APISIX Plugin.

This Plugin addresses common functionalities in phases like init, rewrite, access, balancer, header filter, body filter and log.

echo - 图1WARNING

The echo Plugin is built as an example. It has missing cases and should not be used in production environments.

Attributes

NameTypeRequirementDefaultValidDescription
before_bodystringoptionalBody to use before the filter phase.
bodystringoptionalBody that replaces the Upstream response.
after_bodystringoptionalBody to use after the modification phase.
headersobjectoptionalNew headers to use for the response.

At least one of before_body, body, and after_body must be specified.

Enabling the Plugin

The example below shows how you can enable the echo Plugin for a specific Route:

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "plugins": {
  4. "echo": {
  5. "before_body": "before the body modification "
  6. }
  7. },
  8. "upstream": {
  9. "nodes": {
  10. "127.0.0.1:1980": 1
  11. },
  12. "type": "roundrobin"
  13. },
  14. "uri": "/hello"
  15. }'

Example usage

First, we configure the Plugin as mentioned above. We can then make a request as shown below:

  1. curl -i http://127.0.0.1:9080/hello
  1. HTTP/1.1 200 OK
  2. ...
  3. before the body modification hello world

Disable Plugin

To disable the echo Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 \
  2. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  3. {
  4. "methods": ["GET"],
  5. "uri": "/hello",
  6. "plugins": {},
  7. "upstream": {
  8. "type": "roundrobin",
  9. "nodes": {
  10. "127.0.0.1:1980": 1
  11. }
  12. }
  13. }'