use athene::prelude::*; #[derive(Debug, Serialize,Validate,Deserialize,Default)] pub struct UserController { pub email: String, pub age: u16, } // http://127.0.0.1:7878/api/v1/user #[controller(prefix = "api", version = 1, name = "user")] impl UserController { // http://127.0.0.1:7878/api/v1/user/admin@outlook.com/18 // Uri Path Params #[delete("/{email}/{age}")] pub async fn delete(&self, email: String, age: Option) -> impl Responder { ( StatusCode::OK, format!("email is : {}, and age is : {:?}", email, age), ) } // http://127.0.0.1:7878/api/v1/user/query_get/?email=admin@outlook.com&age=29 // Query Params #[get("/query_get")] pub async fn query_get(&self, email: String, age: u16) -> impl Responder { (200, Json(Self { email, age })) } // http://127.0.0.1:7878/api/v1/user/query/?email=admin@outlook.com&age=19 // Query Params #[get("/query")] pub async fn query(&self, user: Query) -> impl Responder { (200, Json(user.0)) } // http://127.0.0.1:7878/api/v1/user/create // Context-Type : application/json #[post("/create")] async fn create(&self, user: Json) -> impl Responder { Ok::<_, Error>((200, user)) } // http://127.0.0.1:7878/api/v1/user/update // Context-Type : application/x-www-form-urlencoded #[put("/update")] #[post("/update")] async fn update(&self, user: Form) -> impl Responder { Ok::<_, Error>((200, user)) } } #[tokio::main] pub async fn main() -> Result<()> { // Add Router let app = athene::new().router(|r|r.controller(UserController::default())); // Start Server app.listen("127.0.0.1:7878").await }