Routing - Axum - Complete Documentation by ntxm.org

Router - new

Learn how to create an empty Axum Router with Router-new and understand why it is the starting point for every Axum application

Understanding the Router Type Parameter in Axum

Learn what the generic type parameter on Axum's Router means, why it exists, how it works, and how to use it correctly when adding shared state to your application.

The route method on Axum Router

Learn how to use the route method to attach handler functions to specific paths and HTTP methods on an Axum Router

Method Routers in Axum

Learn how to use method routers to handle different HTTP methods like GET, POST, PUT, and DELETE in your Axum application.

routing - get

Learn how to use the routing get function in Axum to register handlers for HTTP GET requests, with complete examples and beginner-friendly explanations.

routing - post

Learn how to route HTTP POST requests in Axum using the post function, with practical examples, method matching, and common pitfalls.

Handling PUT Requests with Axum routing put

Learn how to register PUT request handlers in Axum using routing put, with complete examples and beginner-friendly explanations.

routing patch in Axum

Learn how to register a PATCH route in Axum with the routing patch method, handle partial updates, and write beginner-friendly Rust handlers.

routing delete - Handling DELETE Requests in Axum

Learn what the delete function from axum routing does, how to register DELETE request handlers, and how to build delete routes with path parameters and proper status codes.

routing - any

Learn how to use Axum routing any to handle all HTTP methods on a route, when to choose it over specific method routers, and how to inspect the incoming method inside a handler.

MethodRouter Chaining in Axum

Learn how to attach multiple HTTP methods to a single route path in Axum using MethodRouter chaining, with beginner-friendly examples and explanations.

Static Route Paths in Axum

Learn how to define fixed URL paths in Axum, understand exact matching behavior, handle duplicate routes and trailing slashes, and build a simple server with multiple static endpoints.

Route path parameters

Learn how to define and extract dynamic segments from URLs in Axum routes using path parameters with braces syntax.

The /users/{id} Route Syntax

Understand how to write a route path that captures a single dynamic segment such as a user ID, using the brace parameter syntax in Axum 0.8.

Multiple path parameters in Axum

Learn how to define routes with two or more path parameters in Axum, extract them into handlers, and avoid common ordering and type mistakes.

Fallback Routes in Axum

Learn what fallback routes are in Axum, how they catch requests that match no other route, and how to use them for custom 404 pages, API error responses, and redirects.

MatchedPath extractor name

Learn how to use the MatchedPath extractor in Axum to get the route pattern that matched the current request, with beginner-friendly examples.

OriginalUri extractor in Axum

Learn what the OriginalUri extractor does, why it is needed when routing requests, and how to use it correctly with nested routers and path rewriting.

Understanding Axum's nest Method for Modular Routing

Learn how to use Axum's nest method to organize routes into nested routers with path prefixes, enabling modular and maintainable web applications.

Nest Path Prefix in Axum Routing

Learn how the path prefix works when nesting routers with the nest method in Axum, how prefixes combine, and common patterns for organizing routes.

NestedPath

Learn how to use the NestedPath extractor in Axum to get the prefix a route is nested at.

Organizing Routes with routes/mod.rs in Axum

Learn how to structure Axum route definitions into modular files using a routes/mod.rs module and nest them with path prefixes for clean, maintainable web applications.

Axum Router Merge Method

Learn how to combine multiple Axum routers using the merge method, including modular route organization, overlapping routes, fallbacks, state types, common mistakes, and practical examples.

merge vs nest in Axum Routing

Learn the differences between Router merge and Router nest, when to use each, and how they affect path prefixes, fallbacks, state types, and middleware.

Merging Modular Route Files in Axum

How to split Axum routes into separate files and combine them with Router merge for a clean modular application structure

Brace Param Syntax in Axum

Learn how to define dynamic path parameters with braces like {id} in Axum routes, extract them safely, and avoid common beginner mistakes.

Legacy colon param syntax

Understand the older colon-prefixed path parameter style used in Axum 0.7 and earlier, how it worked, and how to recognize it in existing code.

Migrating Colon Params to Brace Params

Step-by-step guide for updating Axum route path strings from colon syntax to brace syntax when upgrading from Axum 0.7 to 0.8

Brace Catch-All Syntax in Axum

Learn how to use the {*rest} catch-all path parameter in Axum routes to capture multiple URL segments as a single string.

Catch-all wildcard segment

Learn how Axum catch-all wildcard segments match multiple path parts in a single route and how they differ from regular path parameters

Wildcard with static prefix

Learn how to combine a fixed path segment like /static/ with a wildcard capture in Axum routing, including extraction, edge cases, and route precedence.

Wildcard Placement Rules in Axum Routes

Learn why wildcard catch-all segments must always be the final segment in an Axum route path, with clear examples, common mistakes, and practical guidance for absolute beginners.

Empty wildcard match behavior

A wildcard route in Axum never captures an empty string - learn why /static/ and / return 404, and how to handle the base path instead.

Capturing Wildcard as Path String in Axum

Learn how to use the Path extractor to capture wildcard route segments as a String in Axum handlers, including detailed examples, URL decoding behavior, and common beginner mistakes.

Custom 404 fallback handler

Learn how to set a custom 404 Not Found response in Axum using the fallback method, with examples for plain text, HTML, JSON, and custom types

Fallback on Nested Routers

Learn how to set fallback handlers on nested routers in Axum to provide consistent 404 responses for specific route prefixes.

Route precedence when paths overlap

Learn how Axum decides which handler runs when multiple routes could match the same URL path, with static routes winning over dynamic parameters, order independence, and duplicate route errors.

MethodFilter Custom Methods

Learn how to match multiple HTTP methods and custom non-standard methods in Axum routing using MethodFilter, with complete beginner-friendly examples.

API Versioning with Nest

Learn how to organize versioned API routes in Axum using the nest method and the /api/v1 path prefix pattern, including fallback behavior and multiple structuring approaches.