Skip to content

Guide · Open source

How to use axum: install, routes and handlers in Rust

Updated · written with AI from the project's own documentation and checked against our catalogue data

axum is an open-source Rust library for building web servers and HTTP APIs. You map URLs to handler functions, and axum takes care of pulling data out of incoming requests and turning your return values into responses. This guide explains what you need before starting, how to get the source, how routing and handlers fit together, and whether axum suits your project.

axumtokio-rs/axum · ★ 27.7k · MIT

Quick start

  1. 1Install Rust and cargo. Install a Rust toolchain that includes cargo, which is the prerequisite for axum.
  2. 2Clone the repository. Run git clone https://github.com/tokio-rs/axum to get the source, examples and README.
  3. 3Read the full README. The excerpt is truncated, so open the complete README in the cloned folder for setup details.
  4. 4Create a Rust project. Start a new Rust project with cargo so you have a place to write your server code.
  5. 5Define a route and handler. Write an async handler function and attach it to a URL path in your router.
  6. 6Run and test your server. Build and run the project with cargo, then send requests to your routes to check the responses.

What axum is and who it is for

axum is an HTTP routing and request-handling library written in Rust. Its project description emphasizes ergonomics and modularity, meaning the pieces are meant to be easy to use and to combine.

It is a library, not a ready-made application. You write the Rust code that defines your server. It is a good fit for Rust developers building HTTP APIs or web services, and for teams already using the Tokio async runtime. It is less suited to people who do not write Rust, or to projects that need built-in admin, ORM or templating features, which the README excerpt does not show.

What you need before you start

The install method listed for axum is through a package manager, and the prerequisite is a Rust toolchain that includes cargo, Rust's build and package tool.

Because axum is built on the Tokio async runtime, it helps to be comfortable with basic Rust and async code. The README excerpt is a beginner hurdle: its handler model is type-driven, which can take time to learn if you are new to Rust.

  • A Rust toolchain with cargo installed
  • Basic familiarity with Rust
  • Familiarity with Tokio is useful

Get the axum source code

The only install command given in the source is a git clone of the repository. Run it to get a local copy of the code, examples and README.

The README excerpt provided is truncated, so for the exact steps to add axum to your own project, read the full README in the cloned repository.

git clone https://github.com/tokio-rs/axum

Define routes that map URLs to handlers

In axum, a route connects a URL path to a handler function. The handler is an ordinary Rust function that receives extracted data from the request, such as path or query values, and returns something that axum converts into an HTTP response.

Because routes and handlers are separate, you can group related routes into modules and compose them. That modularity is one of the project's stated goals.

  • Write a handler as an async function that returns a value axum can turn into a response
  • Register the handler against a URL path in your router
  • Group related routes into modules and combine them

Check the project before you commit

axum is released under the MIT licence and is written in Rust. Comparable projects include actix-web, warp, rocket and poem. Each has its own style of routing and handlers, so a short trial of two or three on your own routes is a practical way to choose.

If you need a full application with an admin panel, ORM or templating included, axum on its own will not provide those from the excerpt shown here.

  • Licence: MIT
  • Language: Rust
  • Alternatives: actix-web, warp, rocket, poem

What people use it for

  • Building a JSON HTTP API in Rust
  • Adding web endpoints to a service that already runs on Tokio
  • Splitting a large web service into modular route groups
  • Comparing request-handling styles before choosing a Rust web framework

Frequently asked questions

Is axum free to use?

Yes. axum is released under the MIT licence, which is a permissive open-source licence. Check the LICENSE file in the repository for the full terms.

What do I need to install axum?

The listed prerequisite is a Rust toolchain with cargo. The only install command in the source is git clone https://github.com/tokio-rs/axum to get the code.

Is axum a full web framework?

axum is a routing and request-handling library rather than a complete application framework. The excerpt does not show built-in admin, ORM or templating features.

Can I use axum without knowing Rust?

No. axum is a Rust library, so you need to write Rust code. Beginners may find its type-driven handler model hard to learn at first.

What is axum compared to actix-web or warp?

All four are Rust web libraries for HTTP servers. axum focuses on ergonomics and modularity, and it is built on Tokio. Trying a small route in each is the most reliable way to compare them for your project.

Why does my axum project fail to build?

The source does not list specific build errors. Check that your Rust toolchain with cargo is installed and read the full README in the repository for setup requirements.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

axum suits Rust developers who want modular, composable HTTP APIs, especially teams already on Tokio. If you do not write Rust or need a batteries-included framework with admin, ORM or templating, pick a different tool.

Install options & downloads