mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
+2
-14
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user