How to create a web app using rust

The Android team at Google write new modules in Rust.

How to create a web app using rust
Photo by M. Zakiyuddin Munziri / Unsplash

Rust is a modern low level programming language. It was first released in 2010 by the Mozilla Organization. It has grown in popularity over time becoming the go to low level  programming language by many organizations.

The Android team at Google write new modules in Rust. The reason for the switch from languages such as C++ or C is quite simple. Rust was created with security and memory safety in mind. To add to that, Rust is more modern compared to C/C++ it therefore benefits to better syntax.This is from the annoying experience programmers have had with other programming languages.

Rust is not just a programming language. It can also be used to create web applications. In this guide we are going to have a look at different ways one can create a web app with Rust. I will try to be simple but offer the maximum guide.

1. Using Actix Web

One of the best ways to create a web application or an api is using actix web. Actix web is a lightweight framework . It has far been my favorite for creating api's in rust.

In 2020 there were some rumors that actix web was dead. However this has been sorted. In 2020 the actix web active developer decided to move on to other things. The caused some turbulence but that was not the end of the story. The actix-web developer decided to allow someone else to take charge of active development of actix web.

Getting starting with Rust + Actix Web for beginner
Big tech companies such a Google, Microsoft and Netflix use rust. i.e. Google is currently using rust in the development of Android operating system

2. Using Rocket

Rocket is my second favorite rust framework for building web applications. However I feel the team behind the rust rocket framework make rapid changes to the framework. This makes it difficult due to inconsistency in the documentations.

I personally had a problem making my application return a rest api json  object at a go. I had to battle a couple of errors and figure out what version I was on. Rocket feels more matures compared to actix-web in terms of features but immature in terms of stability. In terms of speed there is no notable huge notable difference between Rocket and Actix-web framework. Rocket is as fast as Actix-web. Even though actix-web is much faster.

#[macro_use] extern crate rocket;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![index])
}
Sample rust app with Rocket code
Programming Guide - Rocket Web Framework
Rocket is a web framework for the Rust programming language that makes it simple to write fast web applications without sacrificing flexibility or type safety.

Conclusion

Regardless of your your choice for the rust framework to use, actix-web and rocket are the most popular. They are still young projects and not very suitable for heavy web app development but useful for creating web API's.

Subscribe to Bluedoa Digest

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
alexander@example.com
Subscribe