<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335" -->

---
title: Component Composition with Spin 4.0 · Thorsten Hans
description: A hands-on tutorial walks through building a Spin 4.0 application in Rust that composes two WebAssembly components together: a top-level HTTP-triggered...
canonical: https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Component Composition with Spin 4.0 · Thorsten Hans | daily.dev
og:description: A hands-on tutorial walks through building a Spin 4.0 application in Rust that composes two WebAssembly components together: a top-level HTTP-triggered...
og:url: https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335
og:image: https://api.daily.dev/og/posts/kMT4ts335.png
og:image:alt: Component Composition with Spin 4.0 · Thorsten Hans
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Component Composition with Spin 4.0 · Thorsten Hans

**[Thorsten Hans](https://daily.dev/sources/thorstenhans)** · 7 min read · 1 upvotes · 0 comments

## Summary

A hands-on tutorial walks through building a Spin 4.0 application in Rust that composes two WebAssembly components together: a top-level HTTP-triggered component and a separate 'classifier' component that categorizes message urgency. It covers scaffolding with spin new, creating a headless Rust component template, defining a WIT interface, wiring the component dependency in spin.toml, generating bindings with spin_sdk::dependencies!(), and testing the final app with curl requests.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://thorsten-hans.com/component-composition-with-spin-4>

## Questions this post answers

### How do I declare a Wasm component dependency in spin.toml for Spin 4.0?

Add a table like [component.blog-demo.dependencies] with the component's package name as key and a path to its compiled .wasm file as value, for example "thorstenhans:components@0.1.0" = { path = "./classifier/target/wasm32-wasip2/release/classifier.wasm" }. This tells Spin to link that component as a dependency of the blog-demo component when building.

_Developers wiring up Wasm component dependencies can find similar Spin walkthroughs on daily.dev._

### How do I generate bindings for a Spin component dependency without using wit-bindgen macros directly?

Call the spin_sdk::dependencies!() macro in the component's src/lib.rs, placed before the service definition. The Spin SDK uses this to auto-generate the glue code for imported interfaces declared in spin.toml, pulling functions like classify straight into scope without manually invoking wit-bindgen's generate! macro.

_Anyone stitching Rust Wasm components together can track Spin SDK tips like this on daily.dev._

### What Rust and Spin CLI versions are needed to build composed WebAssembly components with Spin 4.0?

Rust 1.97.2 or newer, the wasm32-wasip2 target added via rustup, and Spin CLI 4.0.2 or newer. These are the minimum tooling requirements for scaffolding an http-rust Spin application and adding a headless Rust sub-component that exports a WIT interface for composition.

_Developers setting up Wasm component toolchains can follow version-specific guides like this on daily.dev._

## Similar posts on daily.dev

- [Out Now: Building Serverless Applications with WebAssembly & Spin · Thorsten Hans](https://daily.dev/posts/out-now-building-serverless-applications-with-webassembly-spin-thorsten-hans-zyyuowu4b) · Thorsten Hans · 0 upvotes · 0 comments
- [I’m Writing a Book on WebAssembly and Spin · Thorsten Hans](https://daily.dev/posts/i-m-writing-a-book-on-webassembly-and-spin-thorsten-hans-pfxbbuawk) · Thorsten Hans · 1 upvotes · 1 comments
- [How To Build WebAssembly Components With the MoonBit Language](https://daily.dev/posts/how-to-build-webassembly-components-with-the-moonbit-language-n35cour1z) · The New Stack · 0 upvotes · 0 comments
- [Build AI Agents with Spin and the OpenAI Agents SDK](https://daily.dev/posts/build-ai-agents-with-spin-and-the-openai-agents-sdk-bkynochho) · Fermyon · 3 upvotes · 0 comments

---

Tags: [#rust](https://daily.dev/tags/rust), [#webassembly](https://daily.dev/tags/webassembly)

[View this post on daily.dev](https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Component Composition with Spin 4.0 · Thorsten Hans","url":"https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335"},"datePublished":"2026-08-14T20:33:10.115Z","dateModified":"2026-09-14T09:12:47.991Z","description":"A hands-on tutorial walks through building a Spin 4.0 application in Rust that composes two WebAssembly components together: a top-level HTTP-triggered...","image":"https://media.daily.dev/image/upload/s--2-1xRawN--/f_auto/v1722860399/public/Placeholder%2011","thumbnailUrl":"https://media.daily.dev/image/upload/s--2-1xRawN--/f_auto/v1722860399/public/Placeholder%2011","isAccessibleForFree":true,"articleSection":"Thorsten Hans","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Thorsten Hans","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ffdd8d9ab69947edb960cdcd6c39e9b2","url":"https://daily.dev/sources/thorstenhans"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust,webassembly","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Thorsten Hans","item":"https://daily.dev/sources/thorstenhans"},{"@type":"ListItem","position":3,"name":"Component Composition with Spin 4.0 · Thorsten Hans"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/component-composition-with-spin-4-0-thorsten-hans-kmt4ts335#faq","mainEntity":[{"@type":"Question","name":"How do I declare a Wasm component dependency in spin.toml for Spin 4.0?","acceptedAnswer":{"@type":"Answer","text":"Add a table like [component.blog-demo.dependencies] with the component's package name as key and a path to its compiled .wasm file as value, for example \"thorstenhans:components@0.1.0\" = { path = \"./classifier/target/wasm32-wasip2/release/classifier.wasm\" }. This tells Spin to link that component as a dependency of the blog-demo component when building. Developers wiring up Wasm component dependencies can find similar Spin walkthroughs on daily.dev."}},{"@type":"Question","name":"How do I generate bindings for a Spin component dependency without using wit-bindgen macros directly?","acceptedAnswer":{"@type":"Answer","text":"Call the spin_sdk::dependencies!() macro in the component's src/lib.rs, placed before the service definition. The Spin SDK uses this to auto-generate the glue code for imported interfaces declared in spin.toml, pulling functions like classify straight into scope without manually invoking wit-bindgen's generate! macro. Anyone stitching Rust Wasm components together can track Spin SDK tips like this on daily.dev."}},{"@type":"Question","name":"What Rust and Spin CLI versions are needed to build composed WebAssembly components with Spin 4.0?","acceptedAnswer":{"@type":"Answer","text":"Rust 1.97.2 or newer, the wasm32-wasip2 target added via rustup, and Spin CLI 4.0.2 or newer. These are the minimum tooling requirements for scaffolding an http-rust Spin application and adding a headless Rust sub-component that exports a WIT interface for composition. Developers setting up Wasm component toolchains can follow version-specific guides like this on daily.dev."}}]}
```

