Skip to main content

controller

Attribute Macro controller 

Source
#[controller]
Expand description

This macro is an alias for defining HTTP controllers. Defines an HTTP controller with a base path, and should be used in combination with the #[routes] macro for route implementation.

§Parameters

  • base_path: The base path for the controller, e.g., “/api

§Usage

#[controller("/base_path")]
struct MyController {}

#[routes]
impl MyController {
    #[get("/sub_path")]
    async fn my_handler(&self) -> HttpResult {
       Ok(JsonResponse::Ok().message("Hello from MyController"))    
    }
}