Crate actix_web_codegen

Source
Expand description

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 main macro docs.

#[actix_web_codegen::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 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 routes macro docs.

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

Attribute Macros§

connect
Creates route handler with actix_web::guard::Connect.
delete
Creates route handler with actix_web::guard::Delete.
get
Creates route handler with actix_web::guard::Get.
head
Creates route handler with actix_web::guard::Head.
main
Marks async main function as the Actix Web system entry-point.
options
Creates route handler with actix_web::guard::Options.
patch
Creates route handler with actix_web::guard::Patch.
post
Creates route handler with actix_web::guard::Post.
put
Creates route handler with actix_web::guard::Put.
route
Creates resource handler, allowing multiple HTTP method guards.
routes
Creates resource handler, allowing multiple HTTP methods and paths.
scope
Prepends a path prefix to all handlers using routing macros inside the attached module.
test
Marks async test functions to use the Actix Web system entry-point.
trace
Creates route handler with actix_web::guard::Trace.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy