https://github.com/albertoimpl/wasm-gateway-filters
Custom Spring Cloud Gateway filter that calls a WebAssembly function written in C from a .wasm file
https://github.com/albertoimpl/wasm-gateway-filters
java spring-cloud-gateway wasm
Last synced: about 1 month ago
JSON representation
Custom Spring Cloud Gateway filter that calls a WebAssembly function written in C from a .wasm file
- Host: GitHub
- URL: https://github.com/albertoimpl/wasm-gateway-filters
- Owner: Albertoimpl
- License: apache-2.0
- Created: 2022-02-15T11:27:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-04T12:30:43.000Z (over 3 years ago)
- Last Synced: 2025-09-06T03:45:46.211Z (9 months ago)
- Topics: java, spring-cloud-gateway, wasm
- Language: JavaScript
- Homepage:
- Size: 90.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring Cloud Gateway and WebAssembly
Creating a custom Spring Cloud Gateway filter that calls a WebAssembly function written in C from a .wasm file using [wasmtime-java](https://wasmtime.dev/).
To run the project:
```shell
./gradlew bootRun
```
To call the function:
```shell
curl localhost:8081/wasm -H"X-CustomSum-x:10" -H"X-CustomSum-y:16" -sI | grep X-CustomSum
X-CustomSum: 26
```
This request will call a custom filter that will sum two digits and add it to the response headers:
```yaml
spring:
cloud:
gateway:
routes:
- uri: https://albertoimpl.com
predicates:
- Path=/wasm
filters:
- StripPrefix=1
- CustomSumWASMFilter
```
To compile the sum function:
```shell
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
```
```shell
emcc sum/sum.c -o sum/sum.js -s EXPORTED_FUNCTIONS='["_sum"]'
```
```shell
cp sum/sum.wasm src/main/resources/
```