2022-01-30 07:50:33 +08:00
< div align = "center" >
2022-10-22 02:33:06 +08:00
< h1 > Fermyon Spin< / h1 >
2023-03-23 22:10:18 +08:00
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "./docs/static/image/logo-dark.png" >
2023-03-23 22:12:34 +08:00
< img alt = "spin logo" src = "./docs/static/image/logo.png" width = "300" height = "128" >
2023-03-23 22:10:18 +08:00
< / picture >
2022-03-07 10:29:36 +08:00
< p > Spin is a framework for building, deploying, and running fast, secure, and composable cloud microservices with WebAssembly.< / p >
2022-03-30 04:05:35 +08:00
< a href = "https://github.com/fermyon/spin/actions/workflows/build.yml" > < img src = "https://github.com/fermyon/spin/actions/workflows/build.yml/badge.svg" alt = "build status" / > < / a >
2022-06-23 16:48:42 +08:00
< a href = "https://discord.gg/eGN8saYqCk" > < img alt = "Discord" src = "https://img.shields.io/discord/926888690310053918?label=Discord" > < / a >
2022-01-30 07:50:33 +08:00
< / div >
2021-12-15 03:21:00 +08:00
2022-03-07 10:29:36 +08:00
## What is Spin?
2021-12-15 03:21:00 +08:00
2022-03-07 10:29:36 +08:00
Spin is an open source framework for building and running fast, secure, and
composable cloud microservices with WebAssembly. It aims to be the easiest way
to get started with WebAssembly microservices, and takes advantage of the latest
developments in the
[WebAssembly component model ](https://github.com/WebAssembly/component-model )
and [Wasmtime ](https://wasmtime.dev/ ) runtime.
2021-12-15 03:21:00 +08:00
2022-03-07 10:29:36 +08:00
Spin offers a simple CLI that helps you create, distribute, and execute
applications, and in the next sections we will learn more about Spin
applications and how to get started.
2021-12-15 03:21:00 +08:00
2022-03-07 10:29:36 +08:00
## Getting started
2021-12-07 13:14:57 +08:00
2023-04-14 02:29:39 +08:00
See the [Install Spin ](https://developer.fermyon.com/spin/install ) page of the [Spin documentation ](https://developer.fermyon.com/spin/index ) for a detailed
guide on installing and configuring Spin, but in short run the following commands:
```bash
curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash
sudo mv ./spin /usr/local/bin/spin
2021-11-03 08:02:05 +08:00
```
2021-12-07 13:14:57 +08:00
2023-04-14 02:29:39 +08:00
Alternatively, you could [build Spin from source ](https://developer.fermyon.com/spin/contributing/ ).
2022-03-23 11:42:00 +08:00
2023-04-14 02:29:39 +08:00
To get started writing apps, follow the [quickstart guide ](https://developer.fermyon.com/spin/quickstart/ ),
and then follow the
2023-03-25 02:19:35 +08:00
[Rust ](https://developer.fermyon.com/spin/rust-components/ ), [JavaScript ](https://developer.fermyon.com/spin/javascript-components ), [Python ](https://developer.fermyon.com/spin/python-components ), or [Go ](https://developer.fermyon.com/spin/go-components/ )
2023-04-14 02:29:39 +08:00
language guides, and the [guide on writing Spin applications ](https://developer.fermyon.com/spin/configuration/ ).
2022-02-06 10:51:48 +08:00
2023-04-14 02:29:39 +08:00
## Usage
2023-04-28 05:57:51 +08:00
Below is an example of using the `spin` CLI to create a new Spin application. To run the example you will need to install the `wasm32-wasi` target for Rust.
2022-02-06 10:51:48 +08:00
2023-03-25 02:19:35 +08:00
```bash
2023-04-14 02:29:39 +08:00
$ rustup target add wasm32-wasi
2021-11-03 08:02:05 +08:00
```
2023-03-25 02:19:35 +08:00
2023-04-14 02:29:39 +08:00
First, run the `spin new` command to create a Spin application from a template.
```bash
# Create a new Spin application named 'hello-rust' based on the Rust http template, accepting all defaults
$ spin new --accept-defaults http-rust hello-rust
2023-03-25 02:19:35 +08:00
```
2023-04-14 02:29:39 +08:00
Running the `spin new` command created a `hello-rust` directory with all the necessary files for your application. Change to the `hello-rust` directory and build the application with `spin build` , then run it locally with `spin up` :
2023-03-25 02:19:35 +08:00
```bash
2023-04-14 02:29:39 +08:00
# Compile to Wasm by executing the `build` command.
2023-03-25 02:19:35 +08:00
$ spin build
2023-04-14 02:29:39 +08:00
Executing the build command for component hello-rust: cargo build --target wasm32-wasi --release
Finished release [optimized] target(s) in 0.03s
2023-03-25 02:19:35 +08:00
Successfully ran the build command for the Spin components.
2023-04-14 02:29:39 +08:00
2023-03-25 02:19:35 +08:00
# Run the application locally.
2022-03-30 04:05:35 +08:00
$ spin up
2023-03-25 02:19:35 +08:00
Logging component stdio to ".spin/logs/"
2023-04-14 02:29:39 +08:00
2023-03-25 02:19:35 +08:00
Serving http://127.0.0.1:3000
Available Routes:
2023-04-14 02:29:39 +08:00
hello-rust: http://127.0.0.1:3000 (wildcard)
2022-01-30 07:50:33 +08:00
```
2023-04-14 02:29:39 +08:00
That's it! Now that the application is running, use your browser or cURL in another shell to try it out:
2023-03-25 02:19:35 +08:00
```bash
2023-04-14 02:29:39 +08:00
# Send a request to the application.
$ curl -i 127.0.0.1:3000
HTTP/1.1 200 OK
foo: bar
content-length: 14
date: Thu, 13 Apr 2023 17:47:24 GMT
Hello, Fermyon
2023-03-25 02:19:35 +08:00
```
2023-04-14 02:29:39 +08:00
You can make the app do more by editting the `src/lib.rs` file in the `hello-rust` directory using your favorite editor or IDE. To learn more about writing Spin applications see [Writing Applications ](https://developer.fermyon.com/spin/writing-apps ) in the Spin documentation. To learn how to publish and distribute your application see the [Publishing and Distribution ](https://developer.fermyon.com/spin/distributing-apps ) guide in the Spin documentation.
2023-03-25 02:19:35 +08:00
2023-04-14 02:29:39 +08:00
For more information on the cli commands and subcommands see the [CLI Reference ](https://developer.fermyon.com/common/cli-reference ).
2023-03-25 02:19:35 +08:00
## Language Support for Spin Features
2023-04-14 02:29:39 +08:00
The table below summarizes the [feature support ](https://developer.fermyon.com/spin/language-support-overview ) in each of the language SDKs.
2023-03-29 04:21:45 +08:00
2023-03-29 04:09:07 +08:00
| Feature | Rust SDK Supported? | TypeScript SDK Supported? | Python SDK Supported? | Tiny Go SDK Supported? | C# SDK Supported? |
|-----|-----|-----|-----|-----|-----|
2023-03-25 02:19:35 +08:00
| **Triggers** |
2023-03-29 04:09:07 +08:00
| [HTTP ](https://developer.fermyon.com/spin/http-trigger ) | Supported | Supported | Supported | Supported | Supported |
| [Redis ](https://developer.fermyon.com/spin/redis-trigger ) | Supported | Not Supported | Not Supported | Supported | Not Supported |
2023-03-25 02:19:35 +08:00
| **APIs** |
2023-03-29 04:09:07 +08:00
| [Outbound HTTP ](https://developer.fermyon.com/spin/rust-components.md#sending-outbound-http-requests ) | Supported | Supported | Supported | Supported | Supported |
2023-09-08 19:14:00 +08:00
| [Configuration Variables ](https://developer.fermyon.com/spin/variables ) | Supported | Supported | Supported | Supported | Supported |
2023-06-17 04:15:53 +08:00
| [Key Value Storage ](https://developer.fermyon.com/spin/kv-store-api-guide ) | Supported | Supported | Supported | Supported | Not Supported |
2023-09-08 19:14:00 +08:00
| [Sqlite Storage ](https://developer.fermyon.com/spin/sqlite-api-guide ) | Supported | Supported | Supported | Not Supported | Not Supported |
2023-03-29 04:09:07 +08:00
| [MySQL ](https://developer.fermyon.com/spin/rdbms-storage#using-mysql-and-postgresql-from-applications ) | Supported | Not Supported | Not Supported | Not Supported | Not Supported |
| [PostgreSQL ](https://developer.fermyon.com/spin/rdbms-storage#using-mysql-and-postgresql-from-applications ) | Supported | Not Supported | Not Supported | Not Supported | Supported |
| [Outbound Redis ](https://developer.fermyon.com/spin/rust-components.md#storing-data-in-redis-from-rust-components ) | Supported | Supported | Supported | Supported | Supported |
2023-09-08 19:14:00 +08:00
| [Serverless AI ](https://developer.fermyon.com/spin/rust-components#ai-inferencing-from-rust-components ) | Supported | Supported | Not Supported | Not Supported | Not Supported |
2023-03-25 02:19:35 +08:00
| **Extensibility** |
2023-03-29 04:13:26 +08:00
| [Authoring Custom Triggers ](https://developer.fermyon.com/spin/extending-and-embedding ) | Supported | Not Supported | Not Supported | Not Supported | Not Supported |
2023-03-25 02:19:35 +08:00
2022-03-07 10:29:36 +08:00
## Contributing
2022-02-01 10:26:51 +08:00
2022-03-07 10:29:36 +08:00
We are delighted that you are interested in making Spin better! Thank you!
2022-12-12 13:53:15 +08:00
Please follow the [contributing guide ](https://developer.fermyon.com/spin/contributing ).
2022-06-27 01:28:08 +08:00
And join our [Discord server ](https://discord.gg/eGN8saYqCk ).
2022-05-10 03:55:56 +08:00
2023-03-25 02:19:35 +08:00
## Stay in Touch
2023-04-14 02:29:39 +08:00
Follow us on Twitter: [@spinframework ](https://twitter.com/spinframework )
You can join the Spin community in our [Discord server ](https://discord.gg/eGN8saYqCk ) where you can ask questions, get help, and show off the cool things you are doing with Spin!
2022-05-10 03:55:56 +08:00