Build a CDB EdgeCompute HTTP application
CDB EdgeCompute HTTP applications respond to HTTP requests directly from the edge. The handler compiles to a WebAssembly binary and runs without servers or containers. Three language options are available — complete the toolchain setup first: Rust (Modern HTTP), Rust (Legacy HTTP), or JavaScript.
Write a handler
Each language uses a different entry point convention. Choose the tab that matches the toolchain set up earlier.
Replace src/lib.rs with:
use wstd::http::body::Body;
use wstd::http::{Request, Response};
#[wstd::http_server]
async fn main(request: Request<Body>) -> anyhow::Result<Response<Body>> {
let url = request.uri().to_string();
Ok(Response::builder()
.status(200)
.header("content-type", "text/plain;charset=UTF-8")
.body(Body::from(format!("Request received: {url}")))?)
}
Build
Compile the handler to a WebAssembly binary. The first build downloads dependencies and takes one to two minutes.
cargo build --release --target wasm32-wasip2
The binary is at ./target/wasm32-wasip2/release/hello_world.wasm.
Deploy
- In the CDB Technical Web Portal, navigate to CDB EdgeCompute > HTTP Applications > Applications and click Create new application.
- Click Upload binary and select the
.wasmfile produced in the Build step. - Enter a Name for the application.
- Click Save and deploy.
The application URL appears on the details page. Test it:
curl -i https://<app-name>-<id>.edgecompute.app/hello