Josh
05 Oct 2018
By Josh

What's in your Larder: Rust web frameworks

I've long had my eye on Rust as a language to try out, and recently I've been playing around with writing a web app and API in Rust. I picked Rocket as my framework, but as the Rust ecosystem is still early, there are a lot of options for frameworks. Each has their own strengths and weaknesses, and to me there's still no clear winner. I thought I'd round up those worth looking at. I've done my best to represent the frameworks accurately, but these are still qualitative assessments, so your opinion may differ :)

Rocket

Rocket is a framework in its teens — more developed than many of the others, but still not quite mature. Its special feature is its use of macros to annotate request handler functions with their routes and provide parameters and required data, such as valid deserialised forms, with a kind of dependency injection. Also, the docs are quite good, development is active, and along with Actix, this is one of the most commonly-used frameworks, so you benefit from increased community knowledge. Rocket requires a nightly version of Rust.

Actix-web

Actix-web is a framework built on Actix, an actor system for Rust. It hasn't been around as long as Rocket, but has gained features quite rapidly and is another community favourite. The unique actor approach means that separate components, like database access and background tasks, are each implemented as asynchronous actors that communicate to each other by message passing. Actix-web is probably best-known for appearing near the top of the TechEmpower Web Framework Benchmarks. Actix-web is under active development and has fairly thorough documentation.

Gotham

Gotham is an asynchronous web framework that I think has been around about as long as Rocket, but in less active development in 2018 as the original developers stepped away. I like its simple, explicit approach, but it could be considered a little verbose for some common tasks, and is falling behind the more popular frameworks lately in terms of features.

Tower-web

Tower-web is another approachable framework that aims to provide all the standard features. It's built on Tower, a library of network client/server components, meaning it should eventually gain "batteries included" status. It's also developed by one of the core contributors to Tokio, Rust's most popular asynchronous runtime library, which seems like a plus. Tower-web, like Rocket, uses macros to reduce boilerplate, but doesn't require nightly Rust. As it's quite new it's still missing features and much in the way of documentation, but is under active development.

Warp

Warp is a framework with the unique angle of composability, allowing you to chain together reusable "filters" for things like parameter extraction and required application state in order to build routes and request handlers. It's also quite new and light on documentation, but under active development. It has a relationship with Tower-web that isn't quite clear to me, but it seems like the developers know each other and may merge Warp and Tower-web as alternative APIs on top of a single framework in future.

Rouille

Rouille is a synchronous micro-framework that provides the building blocks of a web framework and leaves the rest to you. It's small and simple and doesn't have as much in the way of documentation, but does appear to be under active development.

Shio

Shio is an asynchronous micro-framework that has a lot in common with Rouille. It doesn't seem to get a lot of active development and doesn't have a lot in the way of documentation, although it does have some examples.

Nickel

Nickel is a lightweight framework inspired by the Express JavaScript framework. It was one of the first frameworks to appear for Rust and still sees some maintenance, but doesn't appear to be under active development. Its documentation is pretty sparse.

Rustful

Rustful is another micro-framework. It doesn't seem to see much active development, but I've included it here in case it looks like your thing.

Bonus: Yew (Front-end)

Yew takes advantage of Rust's ability to compile to WebAssembly to provide a front-end framework inspired by Elm and React. I've not looked at it in detail but it seems like it has good interop with JavaScript and is mature enough to take for a spin. It doesn't have a lot of docs but does have many examples, and is under active development.

Bonus: Diesel (ORM)

Diesel is the de-facto ORM solution for Rust. It supports migrations, schema generation, and has a nice query building DSL. I had issues using it with MySQL in the past, and it seems like Postgres is the favoured database (fair enough), but development is active and my issue was resolved not long after.