<a id="wasm-core"></a>

# WASM Module

The core module that implements basic WASM functionality in Angie: it includes
support for loading alternative runtimes and WASM modules, as well as
configuring their features and limits.

The other modules in this section extend this functionality, allowing you to
flexibly configure and optimize WASM capabilities for various scenarios and
requirements.

In our repositories, the module is built [dynamically](https://en.angie.software//angie/docs/installation/index.md#install-dynamicmodules)
and is available as a separate package named `angie-module-wasm`.

<a id="configuration-example-75"></a>

## Configuration Example

```none
# These directives load the core functionality
load_module modules/ngx_wasm_module.so;
load_module modules/ngx_wasm_core_module.so;

load_module modules/ngx_wasmtime_module.so;

# Available here: https://git.angie.software/web-server/angie-wasm
load_module modules/ngx_http_wasm_host_module.so;

events {

}

wasm_modules {

    #use wasmtime;

    load ngx_http_handler.wasm id=handler;
    load ngx_http_vars.wasm id=vars type=reactor;
}

http {

    wasm_var vars "ngx:wasi/var-utils#sum-entry" $rvar $arg_a $arg_b $arg_c $arg_d;

    server {

        listen *:8080;

        location / {

            return 200 "sum('$arg_a','$arg_b','$arg_c','$arg_d')=$rvar\n";
        }

        location /wasm {

            client_max_body_size 20M;
            wasm_content handler "ngx:wasi/http-handler-entry#handle-request";
        }
    }
}
```

<a id="directives-84"></a>

## Directives

<a id="index-0"></a>

<a id="load"></a>

### load

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `load` file `id=`identifier [`fs=`host_path:guest_path]... [`api=`api]... [`type=``command` | `reactor`]   |
|------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| Default                                                                                  | —                                                                                                          |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules                                                                                               |

Loads a module from a disk file and assigns it a unique identifier
(required parameter). During loading, verification occurs to ensure the module
can be instantiated.

The directive supports the following parameters:

| `fs`   | Allows the guest to access a directory on the host.<br/>The parameter can be specified multiple times for different directories.                                                                                                                                                                                                                                                       |
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api`  | Explicitly restricts the list of APIs allowed for the module by listing them.<br/>If the module attempts to use unavailable APIs (not listed here),<br/>an "API not found" error is returned.<br/><br/>By default, all APIs are available to the module.                                                                                                                               |
| `type` | Controls the lifecycle of the loaded module.<br/><br/>- In `command` mode, the machine executes once<br/>  and its state is destroyed after execution.<br/>- In `reactor` mode, the machine effectively runs indefinitely,<br/>  allowing code to be executed multiple times.<br/>  This requires careful memory management:<br/>  if resources are not freed, memory leaks can occur. |

<a id="index-1"></a>

<a id="wasm-modules"></a>

### wasm_modules

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wasm_modules` { ... };   |
|------------------------------------------------------------------------------------------|---------------------------|
| Default                                                                                  | —                         |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                      |

A top-level directive that provides the configuration file context
in which WASM directives should be specified.
It can contain commands for loading WASM modules and configuring parameters
specific to a particular runtime.
