6 releases

0.1.4 Oct 17, 2023
0.1.1 Sep 1, 2023
0.1.0 Aug 29, 2023
0.0.4 Jun 22, 2023

#587 in WebAssembly

37 downloads per month

Apache-2.0

66KB
1K SLoC

land-sdk

land-sdk provides api for Runtime.land to run faas function project with http trigger.

Usage

Add this to your Cargo.toml:

[package]
name = "rust-hello-world"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.75"
http = "0.2.9"
land-sdk = "0.1.4"
# wit-component > 0.14.5 is not compatible with wit-bindgen 0.12.0
wit-component = "= 0.14.5"
wit-bindgen = "0.12.0"

[lib]
crate-type = ["cdylib"] # target wasm32-wasi

Example

use land_sdk::http::{Body, Error, Request, Response};
use land_sdk::http_main;

#[http_main]
pub fn handle_request(req: Request) -> Result<Response, Error> {
    let url = req.uri().clone();
    let method = req.method().to_string().to_uppercase();
    Ok(http::Response::builder()
        .status(200)
        .header("X-Request-Url", url.to_string())
        .header("X-Request-Method", method)
        .body(Body::from("Hello Runtime.land!!"))
        .unwrap())
}

License

Apache-2.0


lib.rs:

Rust SDK for Runtime.land.

This SDK is used to develop Runtime.land functions. It provides a set of methods to handle http request and response via land_sdk::http module on Runtime.land.

Hello World

use land_sdk::http::{Body, Error, Request, Response};
use land_sdk::http_main;

#[http_main]
pub fn handle_request(req: Request) -> Result<Response, Error> {
    // read uri and method from request
    let url = req.uri().clone();
    let method = req.method().to_string().to_uppercase();

    // build response
    Ok(http::Response::builder()
        .status(200)
        .header("X-Request-Url", url.to_string())
        .header("X-Request-Method", method)
        .body(Body::from("Hello Runtime.land!!"))
        .unwrap())
}

Dependencies

~1–1.7MB
~33K SLoC