use athene::prelude::*; struct Cookies; // http://127.0.0.1:7878/cookies #[controller] impl Cookies { // http://127.0.0.1:7878/cookies/get_cookies #[get("/get_cookies")] pub async fn get_cookies(&self,cookie_jar: CookieJar) -> impl Responder { let cookie = cookie_jar.get("Cookie1").unwrap(); (200,cookie.to_string()) } // http://127.0.0.1:7878/cookies/set_cookies #[get("/set_cookies")] pub async fn set_cookies(&self) -> impl Responder { let mut cookie = Cookie::new("Cookie1", "athene"); cookie.set_path("/"); let mut cookie2 = Cookie::new("Cookie2", "athene2"); cookie2.set_path("/"); let mut cookie_jar = CookieJar::new(); cookie_jar.add(cookie); cookie_jar.add(cookie2); (200, cookie_jar) } } pub async fn get_cookies(mut req: Request) -> impl Responder { let cookie = req.cookie("test1").unwrap(); let res = Builder::new(); res.status(StatusCode::OK).text(format!("cookie_name = {:?}",cookie.name())) } pub async fn set_cookies(_req: Request) -> impl Responder { let mut cookie = Cookie::new("test1", "athene"); cookie.set_path("/"); let mut cookie2 = Cookie::new("test2", "athene2"); cookie2.set_path("/"); let mut cookie_jar = CookieJar::new(); cookie_jar.add(cookie); cookie_jar.add(cookie2); (200, cookie_jar) } fn cookie_router(r: Router) -> Router { r.get("/set_cookies", set_cookies) .get("/get_cookies", get_cookies) } #[tokio::main] async fn main() -> Result<()> { let app = athene::new(); let app = app.router(cookie_router).router(|r|r.controller(Cookies)); app.listen("127.0.0.1:7878").await }