Attribute Macro route

Source
#[route]
Expand description

The route macro used to define the path and the method for a handler.

Example of a route macro:

#[route(path="/", method="[POST]")]

Here the path is “/” and methods are POST and GET

Full example:

#[route(path="/hello", method="[POST, GET]")]
fn hello_handler(request: &Request) -> Response {
 
    let mut res = Response::new();        
 
    res.insert("<p>Hello, World!</p>");           
 
    res
}

Here the path is “/hello” and the hello_handler function is responsible for handling any requests sent to the path.