Function axum::route[][src]

pub fn route<S, B>(
    description: &str,
    service: S
) -> Route<S, EmptyRouter<S::Error>> where
    S: Service<Request<B>> + Clone
Expand description

Create a route.

description is a string of path segments separated by /. Each segment can be either concrete or a capture:

  • /foo/bar/baz will only match requests where the path is /foo/bar/bar.
  • /:foo will match any route with exactly one segment and it will capture the first segment and store it at the key foo.

service is the Service that should receive the request if the path matches description.

Examples

use axum::prelude::*;

route("/", service);
route("/users", service);
route("/users/:id", service);
route("/api/:version/users/:id/action", service);

Panics

Panics if description doesn’t start with /.