#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

#1294 in Procedural macros

Download history 10/week @ 2024-02-15 18/week @ 2024-02-22 5/week @ 2024-02-29 6/week @ 2024-03-07 8/week @ 2024-03-14 4/week @ 2024-03-21 15/week @ 2024-03-28 15/week @ 2024-04-04 24/week @ 2024-04-11

58 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

~3.5–5.5MB
~97K SLoC