[−][src]Attribute Macro contraband_codegen::controller
#[controller]
Creates a controller.
Syntax: #[controller("path")]
Example
use contraband::{Injectable, controller}; use contraband::core::ContrabandApp; use actix_web::HttpResponse; #[derive(Clone, Injectable)] struct HelloController; #[controller] impl HelloController { #[get] async fn hello_world(self) -> HttpResponse { HttpResponse::Ok().body("Hello world!") } }
When you define an impl
-block with a controller
-attribute both the block and all methods
inside it will be parsed for specific Contraband-attributes. In the example above a
get
-request is defined on the implemented method, this will automatically register it when
connected to a module.
Note: we don't need to import get
since it is parsed by the controller
-attribute
Impl method attributes
Valid method attributes are:
- All HTTP request methods (
get
,post
,put
,delete
,head
,connect
,options
,trace
,patch
)