Skip to content

Latest commit

 

History

History
107 lines (87 loc) · 3.2 KB

echo.md

File metadata and controls

107 lines (87 loc) · 3.2 KB
title keywords description
echo
Apache APISIX
API Gateway
Plugin
Echo
This document contains information about the Apache APISIX echo Plugin.

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.

:::caution WARNING

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

:::

Attributes

Name Type Requirement Default Valid Description
before_body string optional Body to use before the filter phase.
body string optional Body that replaces the Upstream response.
after_body string optional Body to use after the modification phase.
headers object optional New headers to use for the response.

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

Enable Plugin

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

curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "plugins": {
        "echo": {
            "before_body": "before the body modification "
        }
    },
    "upstream": {
        "nodes": {
            "127.0.0.1:1980": 1
        },
        "type": "roundrobin"
    },
    "uri": "/hello"
}'

Example usage

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

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

Delete Plugin

To remove 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.

curl http://127.0.0.1:9180/apisix/admin/routes/1  \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uri": "/hello",
    "plugins": {},
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    }
}'