Rust is an emerging programming language with lots of popularity. More and more companies are adopting to rust every next day. The reason being rust is not your usual generic programming language. It brings something new to the table, that very few popular languages do. Namely Ownership, Borrowing and Lifetimes. which ultimately can make learning Rust intimidating. but once you grasp these core concepts in rust, it enables you to write fast and safe apps with fearless concurrency.

In other words, in rust, unlike C or C++ you don’t need to manage memory manually. Rusts compiler is smart enough to understand which variable gets freed, at what time Without using a GC. Features like these, have enabled rust developers to write fast applications without compromising memory safety, giving birth to high quality software and tools of modern age. This list of modern consist of everything from an OS, to embedded devices, to cross-platform GUI libs to cloud native stuff, and it’s still expanding

In this list, you will notice a huge section on HTTP libs. Rust has made a huge impact in Web domain, mainly because of the aforementioned traits of rust. Because rust provides fearless concurrency, devs are finally able to concentrate on features and let compiler worry about the memory, giving birth to libraries like actix-web providing a flawless performance of whooping 600k req/s on benchmarks, making it one of the fastest web application server on earth.

And this is exactly what we are going to look at today. Managing few Rust learning groups on social networking platforms like Telegram and Reddit I usually notice a common question about web “Which Web framework I should use?”, let’s try to answer this question with taking an overview of famous HTTP libs. Note that although I will try to explain the libs according to their docs/readme’s only, the review will also contain some on my thoughts as well. If I mention x framework is bad you don’t have to agree with me, that’s just my opinion, but I will SURELY love to hear your opinion if it contradicts.

Hyper

It’s basically impossible to not-mention hyper when it comes to HTTP implementations in Rust. Hyper is an old (mature), fast and correct HTTP framework in rust. You can call it father of many major frameworks today. It’s like nodejs’s raw http module. It provides you with basic APIs to start a server and process HTTP requests and responses, it’s your job to figure out how to do the routing and etc stuff. Overall, it’s fast but not really a good choice if you are looking for an enterprise grade full fledged HTTP framework. Good thing about Hyper is it’s very slim, thus fast, supports HTTP/1 and HTTP/2 and also has Async design. So it’s easy to write HTTP frameworks on top of Hyper. which is what many frameworks do.

A simple hyper service look like this:

let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

let make_svc = make_service_fn(|_conn| async {
    Ok::<_, Infallible>(service_fn(handle))
});

let server = Server::bind(&addr).serve(make_svc);

if let Err(e) = server.await {
    eprintln!("server error: {}", e);
}

you see, it’s a bit too low level even for a low programming language. I personally wouldn’t use it for making production ready services. So lets take a look at few east to use frameworks.

Actix

Technically Actix is the name of an actor framework and the name of the HTTP lib that was written on top of actix is actix-web. But it’s pretty common to call it just actix when you are referencing it in terms http framework. Actix is one the fastest web framework. It has seen some drama in open source community already, causing the owner to delete the repository until he transferred the ownership to someone else. Now it’s being maintained by community, and it’s being actively maintained very well. Actix mainly focuses on being a pragmatic framework, without compromising the speed at all. And we can pretty much see that it has achieved it’s goal very well. Writing a simple hello world service in Actix looks like this:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(web::resource("/").to(|| async { "Hello world!" })
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

It’s pretty much clear that this is much better than Hyper. Note that this is just an example with Hello World. Actix has multiple ways of doing routing and writing services. you should definitely check out the docs for more information.

But Overall I think actix is still far from being a complete framework. The problems with actix I have noticed are majorly with documentation.

Tide

Warp

Rocket

Thruster

Gotham

Iron