Skip to main content

controller

Attribute Macro controller 

Source
#[controller]
Expand description

Marks an impl block as an Oxide controller.

Generates a [Controller] trait implementation that registers all route-annotated methods under the given URL prefix.

§Example

#[controller("/api/users")]
impl UserController {
    fn new(state: &AppState) -> Self { /* ... */ }

    #[get("/")]
    async fn list(&self) -> ApiResponse<Vec<User>> { /* ... */ }

    #[get("/{id}")]
    async fn get_one(&self, Path(id): Path<u64>) -> ApiResponse<User> { /* ... */ }
}