Create a Proxy-Wasm filter
Your first Proxy-Wasm filter
Selecting a language
In order to be viable for filter development, your programming language of
choice must meet the following criteria:
- Supports WebAssembly as a build target
- Has a Proxy-Wasm SDK
The following language SDKs are currently well-tested in Kong Gateway,
making them a good choice for your first filter:
Other languages and/or Proxy-Wasm SDKs are theoretically supported but have not
yet been fully tested.
Kong has made Go and Rust Proxy-Wasm filter templates available. They can be used
to start writing your own filters, or to build as they are and get your first
Deploying the filter with Kong
After writing and building the filter, the next steps are to configure Kong to enable Wasm support and add the filter, then associate the filter to a route or a service. You will then be able to start Kong and issue requests that go through the filter.
WebAssembly support must be enabled in Kong Gateway:
wasm_filters_path parameter must be configured in order for
Kong Gateway to load the filter at runtime. This can be any folder
During local development,
when a short feedback loop is desired, you can set this parameter to
your build toolchain’s output directory (wherever the compiled
<filter-name>.wasm file is produced):
$ export KONG_WASM_FILTERS_PATH=/path/to/my_filter/build
Link to a Kong service and route
Now, the next step is to create a Kong Filter Chain entity using the
filter created in the previous step and associate it with a Kong route
or service. This will be done by creating a declarative yaml config file,
- name: my-wasm-service
- name: my-wasm-route
- name: my-wasm-demo
- name: my_filter
"my_greeting": "Hello from Kong using WebAssembly!"
$ export KONG_DATABASE=off
$ export KONG_DECLARATIVE_CONFIG="$PWD/kong.yml"
Now Kong can be started:
$ export KONG_PREFIX="$PWD/wasm-servroot"
$ kong prepare
$ kong start
And the Proxy-Wasm filter is ready to be used:
$ http --headers http://127.0.0.1:8000/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Thu, 03 Aug 2023 19:28:27 GMT
X-Greeting: Hello from Kong using WebAssembly!