Spin Brings WebAssembly To The Cloud
Written by Nikos Vaggalis   
Thursday, 19 January 2023

Spin is a new open source framework for building and running cloud microservices with WebAssembly which run on the Fermyon Cloud. Fermyon has also released an SDK for . NET.

First, WebAssembly was touted as a runtime that would be embedded into every major web browser in order to write code in any language that could be compiled to its bytecode format. Because of that, the popular browsers would be able to execute not just JavaScript but also compiled binaries, hence the second property that was attached to it;the Javascript killer. .

As things progressed, both of those assumptions were debunked. WebAssembly has broken loose of the browser's constraints and can be used for running Microservices or serveless functions or even run Wasm binaries on the command line so that even cross-platform CLI applications can be developed. So rather than kill JavaScript it might even interoperate with it.

But back to WebAssembly for the Cloud. Fermyon has made Spin:

a framework for web apps, microservices, and other server-like applications.

Spin provides the interfaces for writing WebAssembly modules that can do things like answer HTTP requests. One unique thing about Spin is that it is a multi-language framework. Rust and Go both have robust support in Spin, but you can also write Python, Ruby, AssemblyScript, Grain, C/C++, and other languages.

With Spin you reduce the overhead of microservices by factoring out the web server (replaced by a WAGI server) and writing out HTTP handlers in whatever language we want (Rust, C, JavaScript, Python, etc), which are then compiled to WebAssembly. The host runtime will provide the features necessary, such as a filesystem (a highly sandboxed one), outbound HTTP, key/value storage, etc. Therefore we can focus our microservices on handling the business logic , letting the underlying platform to manage all of the HTTP, SSL/TLS, and such.

With Spin you also satisfy the necessary requirements that need to be in place for Cloud computing applications:

  • Strong security
  • Small binary size
  • Fast loading and running
  • Support for many OSes and architectures
  • Interoperability with cloud services

Here’s what a Spin “Hello World” looks like written in Rust:

#[http_component]​
fn hello_world(_req: Request) -> Result<Response> {​
Ok(Response::builder()​
. status(200)​
. body(Some("Hello, Fermyon!". into()))?)​
}​

Writing a Spin module is not much different in Go:

func main() {
spin. HandleRequest(func(w http. ResponseWriter, r *http. Request) {
fmt. Fprintln(w, "Hello, Fermyon!")
})
}

Spin v0. 7. 0 version of the framework released last month comes with:

  • HashiCorp Vault integration for secrets
  • Support of connecting to MySQL databases from Spin applications.
  • New Spin SDKs for JavaScript and TypeScript

Fermyon has also released an SDK for . NET which can be used to:

  • Build Web applications and microservices using the Spin executor
  • Send HTTP requests to external hosts
  • Read and update Redis stores
  • Query and update PostgreSQL databases

So there you have it, WebAssembly as a better, lighter alternative to VM's, containers and Kubernetes.

 

More Information

Fermyon Spin

Introducing Spin

A simple URL shortener built with Spin

Related Articles

Blazor WebAssembly Crash Course

 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


ChatGPT Coming Soon To Azure OpenAI Services
18/01/2023

Microsoft's Azure OpenAI Service, which has been restricted to a few select customers since its launch in November 2021, is now generally available. The line up of advanced AI models the service offer [ ... ]



Responsible AI Course Free From Amazon
05/01/2023

Bias and fairness have become important issues as AI and machine learning continue to take over decisions in all walks of life. Amazon's Machine Learning University has added a new course addressing t [ ... ]


More News

picobook

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 19 January 2023 )