wasm_call

The `wasm_call` directive executes a specified WebAssembly function at a designated NGINX request phase.

Syntaxwasm_call phase module function;
Defaultnone
Contexthttp, server, location
Arguments3

Description

The wasm_call directive is used within the NGINX configuration to invoke WebAssembly functions during specific execution phases of a request. This allows server-side logic to be written in WebAssembly for flexibility and performance. The syntax requires three parameters: the first is the phase of the request lifecycle (e.g., access, header, etc.), the second is the name of the WebAssembly module that has been previously loaded using the wasm directive, and the third is the specific function within that module that should be called.

When configured, NGINX will pause during the specified phase to execute the function in the defined WebAssembly module. This execution can modify the request, response, or even perform logging or analytics tasks, depending on the function's implementation. The wasm_call directive helps in creating dynamic behavior in NGINX, enabling developers to extend the server's functionality without modifying the source code directly and leveraging the capabilities of WebAssembly.

Config Example

http {
    server {
        listen 9000;

        location / {
            # Calls the 'check_something' function of 'my_module' during the access phase
            wasm_call access my_module check_something;
            proxy_pass http://backend;
        }
    }
}

Ensure that the specified phase is valid and recognized by NGINX, or the directive may not function as expected.

Confirm that the WebAssembly module has been previously defined using the wasm directive before trying to call its functions.

Verify that the function name provided exists in the WebAssembly module; otherwise, execution will fail.

← Back to all directives