#actix-web #routes #const #macro #run-time #routing #path

macro actix-web-codegen-const-routes

Routing and runtime macros for Actix Web with support for const routes

1 unstable release

0.2.0 Oct 14, 2023

#1274 in Procedural macros

Download history 11/week @ 2024-03-13 4/week @ 2024-03-20 12/week @ 2024-03-27 16/week @ 2024-04-03 26/week @ 2024-04-10 4/week @ 2024-04-17 16/week @ 2024-04-24 1/week @ 2024-05-08 4/week @ 2024-05-15 6/week @ 2024-05-22 194/week @ 2024-05-29 639/week @ 2024-06-05 54/week @ 2024-06-12 91/week @ 2024-06-19 56/week @ 2024-06-26

1,020 downloads per month

MIT/Apache

31KB
547 lines

actix-web-codegen-const-routes

Routing and runtime macros for Actix Web with support for const routes. Fork of actix-web-codegen

status-badge

Documentation & Resources

  • API Documentation TODO: replace with fork's documentation link
  • Minimum Supported Rust Version (MSRV): 1.54

Compile Testing

Uses the trybuild crate. All compile fail tests should include a stderr file generated by trybuild. See the workflow section of the trybuild docs for info on how to do this.


lib.rs:

Routing and runtime macros for Actix Web.

Actix Web Re-exports

Actix Web re-exports a version of this crate in it's entirety so you usually don't have to specify a dependency on this crate explicitly. Sometimes, however, updates are made to this crate before the actix-web dependency is updated. Therefore, code examples here will show explicit imports. Check the latest actix-web attributes docs to see which macros are re-exported.

Runtime Setup

Used for setting up the actix async runtime. See [macro@main] macro docs.

#[actix_web_codegen_const_routes::main] // or `#[actix_web::main]` in Actix Web apps
async fn main() {
    async { println!("Hello world"); }.await
}

Single Method Handler

There is a macro to set up a handler for each of the most common HTTP methods that also define additional guards and route-specific middleware.

See docs for: GET, POST, PATCH, PUT, DELETE, HEAD, CONNECT, OPTIONS, TRACE

#[get("/test")]
async fn get_handler() -> HttpResponse {
    HttpResponse::Ok().finish()
}

Multiple Method Handlers

Similar to the single method handler macro but takes one or more arguments for the HTTP methods it should respond to. See [macro@route] macro docs.

#[route("/test", method = "GET", method = "HEAD")]
async fn get_and_head_handler() -> HttpResponse {
    HttpResponse::Ok().finish()
}

Multiple Path Handlers

Acts as a wrapper for multiple single method handler macros. It takes no arguments and delegates those to the macros for the individual methods. See [macro@routes] macro docs.

#[routes]
#[get("/test")]
#[get("/test2")]
#[delete("/test")]
async fn example() -> HttpResponse {
    HttpResponse::Ok().finish()
}

Dependencies

~1.7–2.5MB
~46K SLoC