May 16, 2023

Announcing Spin v1.2

Kate Goldenring Kate Goldenring

spin wasm wasi rust

Announcing Spin v1.2

Today, we are happy to announce Spin 1.2 which includes several enhancements to Spin:

  • Expansion to the Rust key/value SDK to more easily get and set data structures using Serde.
  • Updates to spin watch to better support watching changes in Spin apps with multiple components.
  • Ability to store key/value pairs in Azure CosmosDB.
  • Fuller test coverage, updates to the Go SDK, and more descriptive CLI errors.

Let’s have a look at a few of the highlights of the release!

Get and Set Structures in Key/Value Stores

To ease the ability to set and get structures in key-value stores, get_json and set_json functions were added to the Rust key-value SDK. Now, you just need to tag your structures with the appropriate Serde capabilities and the SDK will do the heavy lifting of serializing and deserializing objects to and from the key-value stores:

use anyhow::Result;
use serde::{Deserialize, Serialize};
use spin_sdk::{
    http::{Request, Response},
    http_component,
    key_value::Store,
};

// Define a Cat object using Serde derive
#[derive(Serialize, Deserialize, Debug)]
struct Cat {
    color: String,
}

#[http_component]
fn handle_request(_req: Request) -> Result<Response> {
    // Open the default key-value store
    let store = Store::open_default()?;
    // Create an instance of a cat object
    let cat = Cat {
        color: "calico".into(),
    };
    // Store the user object using the "rufus" key
    store.set_json(String::from("rufus"), &user)?;
    // Retrieve the user object from the key-value store, using the "rufus" key
    let rufus_the_cat: Cat = store.get_json("rufus")?;
    // Respond to the request by revealing the cat's color as the response body
    Ok(http::Response::builder()
        .status(200)
        .body(Some(rufus_the_cat.color.into()))?)
}

Spin Watch Improvements

Spin’s watch command rebuilds and restarts Spin applications whenever files change. You can use the spin watch command in place of the spin build and spin up commands, to build, run and then keep your Spin application running without manual intervention while staying on the latest code and files. This release features improvements to spin watch to ensure more precise rebuilding of applications, better support multi-component applications and remove bugs.

See Spin’s developer documentation to get started using spin watch today!

Azure Cosmos DB Key/Value Store

Spin provides built-in key-value storage. This storage is backed by an SQLite database embedded in Spin by default. However, the Spin runtime configuration file (runtime-config.toml) can be updated to use different backing stores, such as Redis or now CosmosDB. To update your default store to use CosmosDB instead of SQlite, change the type to azure_cosmos and specify your database account details:

[key_value_store.default]
type = "azure_cosmos"
key = "<key>"
account = "<cosmos-account>"
database = "<cosmos-database>"
container = "<cosmos-container>"

Note: The CosmosDB container must be created with the default partition key, /id.

⌛ This feature was slightly delayed and released in v1.2.1

Thank you!

We would like to thank the almost 60 contributors to the Spin project and in particular our new contributors @ThorstenHans, @Patrick0308, @suneetnangia, and @qtfkwk. Hope to see you again in the commit history soon!

A special mention goes out to the maintainers of the Bytecode Alliance projects, particularly the Wasmtime project, as well as the developers working on WASI and the WebAssembly component model. Their work is instrumental in supporting Spin.

If you are interested in Spin, Fermyon Cloud, or other Fermyon projects, join the chat in the Fermyon Discord server and follow us on Twitter @fermyontech and @spinframework!

Announcing Spin 1.2


🔥 Recommended Posts


Quickstart Your Serveless Apps with Spin

Get Started