Examples readme (#25)

* Examples readme

* link?
This commit is contained in:
David Pedersen
2021-06-19 14:06:49 +02:00
committed by GitHub
parent 44577a0108
commit 8d8cc3ba3d
7 changed files with 16 additions and 30 deletions
+2 -14
View File
@@ -1,13 +1,10 @@
use awebframework::prelude::*;
use http::StatusCode;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
// build our application with some routes
let app = route("/", get(handler)).route("/greet/:name", get(greet));
// build our application with a route
let app = route("/", get(handler));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
@@ -21,12 +18,3 @@ async fn main() {
async fn handler() -> response::Html<&'static str> {
response::Html("<h1>Hello, World!</h1>")
}
async fn greet(params: extract::UrlParamsMap) -> Result<String, StatusCode> {
if let Some(name) = params.get("name") {
Ok(format!("Hello {}!", name))
} else {
// if the route matches "name" will be present
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
}