mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Change routing DSL
This commit is contained in:
+4
-10
@@ -2,20 +2,14 @@ use http::{Request, StatusCode};
|
||||
use hyper::Server;
|
||||
use std::net::SocketAddr;
|
||||
use tower::make::Shared;
|
||||
use tower_web::{body::Body, extract, response::Html};
|
||||
use tower_web::{body::Body, response, get, route, AddRoute, extract};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// build our application with some routes
|
||||
let app = tower_web::app()
|
||||
.at("/")
|
||||
.get(handler)
|
||||
.at("/greet/:name")
|
||||
.get(greet)
|
||||
// convert it into a `Service`
|
||||
.into_service();
|
||||
let app = route("/", get(handler)).route("/greet/:name", get(greet));
|
||||
|
||||
// run it with hyper
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
@@ -24,8 +18,8 @@ async fn main() {
|
||||
server.await.unwrap();
|
||||
}
|
||||
|
||||
async fn handler(_req: Request<Body>) -> Html<&'static str> {
|
||||
Html("<h1>Hello, World!</h1>")
|
||||
async fn handler(_req: Request<Body>) -> response::Html<&'static str> {
|
||||
response::Html("<h1>Hello, World!</h1>")
|
||||
}
|
||||
|
||||
async fn greet(_req: Request<Body>, params: extract::UrlParamsMap) -> Result<String, StatusCode> {
|
||||
|
||||
Reference in New Issue
Block a user