Implementing GET user
Let's look at the steps to implement this:
- We'll start with the basics by implementing the
get_user()
function insrc/routes/user.rs
:#[get("/users/<_uuid>", format = "text/html")] pub async fn get_user(mut _db: Connection<DBConnection>, _uuid: &str) -> HtmlResponse { todo!("will implement later") }
Before we implement get_user()
, we want to prepare the other routines that we will use. For example, we want to return HTML, so we need to create a const
of &'static str
in the same src/routes/user.rs
file as our HTML template.
- We will create two separate instances of
const
so we can insert different contents between the HTML prefix and suffix:const USER_HTML_PREFIX: &str = r#"<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Our Application User</title> </head>...