

Minimalist Guide to Axum
source link: https://tech.marksblogg.com/axum-rust-web-framework.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Minimalist Guide to Axum
Mark Litwintschik
I have 15 years of consulting & hands-on build experience with clients in the UK, USA, Sweden, Ireland & Germany. Past clients include Bank of America Merrill Lynch, Blackberry, Bloomberg, British Telecom, Ford, Google, ITV, LeoVegas, News UK, Pizza Hut, Royal Mail, T-Mobile, Williams Formula 1, Wise & UBS. I hold both a Canadian and a British passport. My CV, Twitter & LinkedIn.
This post is a part of a series exploring Rust-based Web Frameworks.
Axum is a web framework written in Rust. It provides an API for building web applications and helps remove much of the underlying detail of the libraries it's built upon.
The project is primarily the work of David Pedersen, a software engineer at the Stockholm-based video game studio Embark Studios. Axum belongs to the Tokio organisation on GitHub which also hosts an asynchronous runtime for Rust by the same name that has seen 57M downloads and is the 58th most downloaded crate of all time.
Work on Axum began a little over a year ago and has since seen 107 contributors work on the project. It's made up of 13K lines of Rust, has amassed almost 1.6 million downloads on crates.io and has 1,460 closed issues on GitHub.
The documentation is largely a single page with code examples and links to an extensive repository of 39 example projects. These examples are religiously kept up to date as the project develops and matures.
In this post, I'll take a look at some of Axum's features and characteristics.
Axum Up & Running
The system used in this post is running Ubuntu 20.04 LTS. I'll use Rustup to install Rust version 1.62.0.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
I'll clone Axum's Repository and launch the chat example.
$ git clone https://github.com/tokio-rs/axum
$ cd axum/examples
$ cargo run -p example-chat
Opening http://127.0.0.1:3000/ in a web browser will present you with a form asking you to set a username and join a chat group. After doing so, you'll be able to send messages into a single chat channel via WebSockets.
The above uses 102 lines of Rust and a single 43-line HTML file with no external dependencies. Despite the concise size of the code, it's one of the larger examples.
When I compiled a release version of the above it resulted in a 2 MB binary when GZIP-compressed. I'm sure research into stripping this binary down further would bear fruit.
Features & Support
There is an example demonstrating how to use SQLx with Axum. SQLx provides asynchronous support for communicating with PostgreSQL, MySQL, SQLite and MSSQL. I haven't come across any ORMs being demonstrated in the examples but Axum doesn't appear to be too opinionated on external data access.
There is an example demonstrating support for TLS via Rustls. Rustls supports TLS 1.2 and 1.3 and Curve25519, a safe elliptic curve also used by WireGuard. Last year curl added support for Post-Quantum TLS but as of this writing, I can't see any support in Rustls for curl's supported algorithms.
The Askama template rendering engine, which is based on Jinja, is supported. I couldn't find examples for any other templating engine but templates appear to be reasonably decoupled in the example where Askama's use is demonstrated.
I couldn't find any examples or mention of Zstandard or Brotli in the Axum code base. It could be at this point that Axum would be better placed behind a dedicated reverse proxy if this sort of support is important to you.
It doesn't appear that Axum aims to be a "batteries included" framework and prefers to be non-opinionated compared to some of its Rust-based counterparts. For anyone familiar with the Python world's web frameworks, Axum is more like Flask and less like Django. David said himself that the examples provided by the project are not intended to define best practice, but merely be an example of how you might go about implementing a given feature.
Benchmarking Axum
I came across a synthetic benchmark comparing several web frameworks and Axum seems to break away from the Rust-based pack as the number of concurrent requests increases. In the highest concurrent setting benchmarked, Axum came second only to warp among its Rust-based competitors.
Of the 250+ benchmarks across all the languages listed, Axum came 30th overall when ranked by the highest concurrent setting.
Copyright © 2014 - 2022 Mark Litwintschik. This site's template is based off a template by Giulio Fidente.
Recommend
-
4
Combining Axum, Hyper, Tonic, and Tower for hybrid web/gRPC apps: Part 4 By Michael Snoyman, September 20, 2021 Share this
-
49
Share this This is the third of four posts in a series on combining web and gRPC services into a single service using Tower, Hyper, Axum, and Tonic. The full four parts are:
-
34
Share this This is the second of four posts in a series on combining web and gRPC services into a single service using Tower, Hyper, Axum, and Tonic. The full four parts are:...
-
97
Web api benchmarking: Rust (Axum) vs Rust (Warp) Back KR Skip navigation ...
-
5
Hostname based router with axum in Rust Mon, Apr 18, 2022 axum's router does not natively support hostname-based routing, which may be useful if you need to serve mult...
-
9
Axum框架自动处理请求的神奇函数 解道Jdon ...
-
6
Announcing axum 0.6.0Back in August we announced axumrc1...
-
3
Integrating the Rust Axum Framework with Cloudflare Workers Home Public
-
11
Create an RSS Feed in Axum or Leptos2023-09-29 02:00:00 UTC
-
10
Announcing smol-macros, smol-hyper and smol-axum smol just became a much easier choice to build web servers.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK