Skip to main content

echo

Replaces or wraps the upstream response body and adds response headers, for testing.

Category GeneralAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin echoPriority 412

What it does​

echo changes the body and headers of the answer a route gives, for testing. Body replaces the backend's response body with your text, Before body and After body add text in front of it and after it, and Headers adds headers.

The request still reaches the backend, and the client keeps the status it answered with. When no backend answers, the client gets 502 carrying your text in place of the body.

When to use it​

  • Trying out on a test route what a client sees once the answer's body changes, before you set up response-rewrite on the orders API.
  • Marking the answers of a test route with a header, so that testers can tell them apart.
  • Wrapping the backend's answer in text before and after it, to see how a client copes with a body it did not expect.

Not for rewriting the answers of a route your clients rely on — see response-rewrite (Rewrites the response status, headers and body), answering with a made-up response and no backend at all — see mocking (Answers requests with a mocked response instead of an upstream) or making a route fail or slow on purpose — see fault-injection (Injects delays or fixed responses for testing).

Set it up​

Replace the backend's response body with a fixed text​

The request still reaches the backend and its status is kept; only the body and the headers named here change.

Set Body to accepted and fill Headers as in the JSON below.

echo · as the console saves it
{
"body": "accepted",
"headers": {
"Content-Type": "text/plain"
}
}

Things to know​

  • Body — The backend still receives the request and its status stays: with accepted as the body, a request is answered 200 with accepted.
  • Body — The gateway's own answers are rewritten too. When the backend refuses the connection, the client gets 502 carrying accepted.
  • Headers — A header named here is the one the client gets: with Content-Type at text/plain, the answer carries Content-Type with text/plain.
  • Headers — A value is a text or a number. Any other value, true for example, is refused when you save.
  • Headers alone are refused when you save: the plugin needs Body, Before body or After body.
  • AdviceKeep echo on a test route of its own, not on a route your clients call.

Settings​

The fields as the console shows them, section by section.

BodybodystringRequired unless Before body or After body is set

Replaces the upstream response body with this text.

Before bodybefore_bodystringRequired unless Body or After body is set

Text added in front of the response body.

After bodyafter_bodystringRequired unless Before body or Body is set

Text added after the response body.

Headersheadersobject

Headers added to the response. An object whose keys are any name, each with a string or number as its value.

at least 1 key

Every plugin also has Enabled, Priority, Filter, Error response and Pre-function: see Plugin execution settings.

G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.
Facts
Category
General
Add it to
Route, Service, Consumer, Consumer group, Global rule, Plugin config
Engine plugin
echo
Priority
412