mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-22 00:00:17 +02:00
Simplify things quite a bit
This commit is contained in:
@@ -7,15 +7,17 @@
|
||||
// Just using this file for manual testing. Will be cleaned up before an eventual merge
|
||||
|
||||
use axum::{response::IntoResponse, Router};
|
||||
use axum_extra::routing::{typed_path, RouterExt};
|
||||
use axum_extra::routing::RouterExt;
|
||||
use axum_macros::TypedPath;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.with(typed_path::get(users_index).post(users_create))
|
||||
.with(typed_path::get(users_show));
|
||||
.typed_get(users_index)
|
||||
.typed_post(users_create)
|
||||
.typed_get(users_show)
|
||||
.typed_get(users_edit);
|
||||
|
||||
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
@@ -33,6 +35,10 @@ struct UsersMember {
|
||||
id: u32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/users/:id/edit")]
|
||||
struct UsersEdit(u32);
|
||||
|
||||
async fn users_index(_: UsersCollection) -> impl IntoResponse {
|
||||
"users#index"
|
||||
}
|
||||
@@ -44,3 +50,7 @@ async fn users_create(_: UsersCollection, _payload: String) -> impl IntoResponse
|
||||
async fn users_show(UsersMember { id }: UsersMember) -> impl IntoResponse {
|
||||
format!("users#show: {}", id)
|
||||
}
|
||||
|
||||
async fn users_edit(UsersEdit(id): UsersEdit) -> impl IntoResponse {
|
||||
format!("users#edit: {}", id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user