Skip to content

v0.4.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 16 Mar 23:30
· 38 commits to main since this release
bc857ab

Announcing slight v0.4.0, which includes several new features and improvements.

New Features:

  • NATS is now available as a new service for the messaging capability. This feature was added by @danbugs in pull request #354.

Breaking Change:

The http-server capability now builds on WASI Reactor model. This basically means that the rust program that uses http-server capability will need to be created as a rust library instead of a binary program.

To get started, execute the command: cargo new --lib spidey. This will create a rust library.

The Cargo.toml will then look like

[package]
name = "spidey"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1"
# ^^^ Flexible concrete Error type built on std::error::Error
wit-bindgen-rust = { git = "https://github.com/fermyon/wit-bindgen-backport" }
# ^^^ A language binding generator for WebAssembly interface types
wit-error-rs = { git = "https://github.com/danbugs/wit-error-rs", rev = "05362f1a4a3a9dc6a1de39195e06d2d5d6491a5e" }
# ^^^ Convenience error-related trait implementations for types generated from a wit-bindgen import
slight-http-handler-macro = { git = "https://github.com/deislabs/spiderlightning", tag = "v0.4.0" }
# ^^^ Macro for creating http request handlers when using SpiderLightning's http interface
slight-http-server-macro = { git = "https://github.com/deislabs/spiderlightning", tag = "v0.4.0" }

Last, a simply http-server looks like

use anyhow::Result;

use keyvalue::*;
use http_server::*;

use slight_http_handler_macro::register_handler;
use slight_http_server_macro::on_server_init;

wit_bindgen_rust::import!("wit/keyvalue_0.4.0/keyvalue.wit");
wit_bindgen_rust::import!("wit/http-server_0.4.0/http-server.wit");
wit_bindgen_rust::export!("wit/http-server_0.4.0/http-server-export.wit");
wit_error_rs::impl_error!(http_server::HttpRouterError);
wit_error_rs::impl_error!(keyvalue::KeyvalueError);

#[on_server_init]
fn main() -> Result<()> {
    let router = Router::new()?;
    let router_with_route = router.get("/hello", "handle_hello")?;
    let _ = Server::serve("0.0.0.0:3000", &router_with_route)?;
    Ok(())
}

#[register_handler]
fn handle_hello(req: Request) -> Result<Response, HttpError> {
    println!("I just got a request uri: {} method: {}", req.uri, req.method);

    let container = Keyvalue::open("my-container").unwrap();
    let res = container.get("key1");
    let body = match res {
        Ok(value) => value,
        Err(e) => "".as_bytes().to_vec(),
    };

    Ok(Response {
        headers: Some(req.headers),
        body: Some(body),
        status: 200,
    })
}

Improvements:

The handle_run function now accepts io redirect paths, thanks to @devigned's contribution in pull request #342.

We encourage all users to upgrade to this latest version to take advantage of these new features and improvements. Thank you to all of our contributors who made this release possible!

What's Changed

  • added NATS - a new implementor for the messaging capability! by @danbugs in #354
  • enable handle_run to accept io redirect paths by @devigned in #342
  • feat(http-server): Add WASI reactor support to http-server cap by @Mossaka in #359
  • ci: Remove restaurant-backend and updated CI to build examples by @Mossaka in #362
  • made supported capabilities msg more maintaible by @danbugs in #357
  • chore: bump to 0.4.0 by @Mossaka in #363

Full Changelog: v0.3.3...v0.4.0