use ::{models, utils}; use rocket_contrib::Json; #[derive(BartDisplay, Serialize)] #[template = "templates/index.html"] struct IndexTemplate<'a> { title: &'a str, posts: Vec } implement_responder_for!(IndexTemplate<'a>); #[get("/", format = "text/html")] fn index<'a>(conn: utils::DbConn) -> IndexTemplate<'a> { IndexTemplate { title: "Bloggen", posts: models::Post::get_all(conn) } } #[get("/", format = "application/json")] fn index_json(conn: utils::DbConn) -> Json> { Json(models::Post::get_all(conn)) }