[dependencies]
...
serde_urlencoded = "0.7.0"
Using Third-Party Libraries
To view an example policy project that uses third-party libraries, see Crypto Policy Example. |
Proxy Wasm defines a low level binary application interface (abi), that limits the system calls a library can make. All third-party libraries included in your policy must be compatible with the wasm32-wasi
Rust compilation target.
To define a library such as serde_urlencoded
, add it to the dependency list in cargo.toml
:
Defining libraries enables you to use functions in lib.rs
such as:
serde_urlencoded::to_string([("token", "myToken")])
Libraries that interact with an external service like a database, or perform a system call like reading a file, are usually not compatible with the wasm32-wasi
target.
If your policy interacts with external services, use the Flex Gateway exposed HttpClient
. For more information about performing an HTTP call, see Performing an HTTP Call.
It is possible that some libraries compile properly to the wasm32-wasi
target but don’t work properly when deployed to Flex Gateway. Example errors include:
-
Failed to load Wasm module due to a missing import: …
-
Wasm VM failed to initialize Wasm code
-
Plugin configured to fail closed failed to load
In these cases, contact the owners of the third-party library, or use a different library.