liveBook · Manning

Spin

As explained in Server-Side WebAssembly

Spin is an open-source framework and runtime for building and running WebAssembly applications, especially event-driven services.

Spin is a framework and runtime for running WebAssembly applications as event-driven microservices. It provides an off-the-shelf host, SDKs, templates, and a developer toolchain so applications can focus on business logic instead of custom host construction. section 6.0 section 6.5

A Spin application connects events to WebAssembly components through an application manifest:

  • Choose a template with spin new, including HTTP and Redis handlers for Rust, Go, JavaScript, TypeScript, Python, .NET, and other languages. section 6.5.1
  • Define the application, components, routes, source files, build command, and outbound-host permissions in spin.toml. section 6.5.1
  • Map triggers such as HTTP requests or Redis messages to the components that handle them. section 6.5.1
  • Build with spin build and run locally with spin up; Spin serves the configured route and logs component output. section 6.5.1

Rust HTTP hello world

Selecting the http-rust template creates hello-world-spin with Cargo.toml, spin.toml, and src. The generated handler uses the Spin HTTP SDK, prints the request URL, and returns a 200 response containing “Hello World!”. After spin build and spin up, curl http://127.0.0.1:3000 verifies the route. Spin creates request-handling instances by default; oha can benchmark concurrent requests. section 6.5.1 section 6.5.2

spin new

Use the Spin project-generation command to select an HTTP, Redis, static-file, or language-specific starter template. section 6.5.1

How Server-Side WebAssembly covers it

How deep it goes
Defines templates, manifests, triggers, SDK handlers, build commands, and concurrency, but stops short of multi-host scaling implementation.
Examples
Uses a Rust HTTP hello-world component, spin.toml, curl, and an oha concurrency benchmark.
What it assumes
Requires Rust 1.85.0 or later for the examples, while providing templates and SDKs for multiple programming languages.
What you can do after
Build it from scratch with Spin templates, compile a WebAssembly component, run it locally, and test its HTTP route.
How it connects
Connects WebAssembly components with HTTP, Redis, WASI, Rust, wasmCloud, and Kubernetes through SpinKube.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.