3 releases
0.1.2 | Sep 22, 2019 |
---|---|
0.1.1 | Sep 16, 2019 |
0.1.0 | Sep 16, 2019 |
#1493 in Procedural macros
4KB
Actix web flask decorator
- Cargo package: awf-help
Example
extern crate awf_help;
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use awf_help::{config, route,route_res, ServiceFactory};
#[route(GET, "/")]
fn greet(req: HttpRequest) -> String {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
struct Hello{
}
#[route_res("/api/auth")]
impl Hello {
fn get(req: HttpRequest) -> String {
format!("get Hello !")
}
fn post(req: HttpRequest) -> String {
format!("post Hello !")
}
}
fn main() {
HttpServer::new(|| App::new().configure(config))
.bind("127.0.0.1:8000")
.expect("Can not bind to port 8000")
.run()
.unwrap();
}
lib.rs
:
This is documentation for the awf-help
crate.
Examples
Cargo.toml add
[dependencies]
awf-help = "0.1"
actix-web = "1.0"
inventory = "0.1"
import namespace
extern crate awf_help;
use awf_help::{config, route,route_res, ServiceFactory};
config webservice
HttpServer::new(|| App::new().configure(config))
.bind("127.0.0.1:8000")
.expect("Can not bind to port 8000")
.run()
.unwrap();
add decorator
#[route(GET, "/")]
fn greet(req: HttpRequest) -> String {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
#[route(POST, "/")]
#[route(HEAD, "/")]
#[route_res("/hello")]
impl Hello {
fn get(req: HttpRequest) -> String {
format!("get Hello !")
}
fn post(req: HttpRequest) -> String {
format!("post Hello !")
}
}
Dependencies
~24MB
~526K SLoC