Implement path extractor (#124)

Fixes #42
This commit is contained in:
Sunli
2021-08-06 10:17:57 +02:00
committed by GitHub
parent 2be79168d8
commit 9fdbd42fba
14 changed files with 871 additions and 66 deletions
+3 -6
View File
@@ -14,7 +14,7 @@
//! ```
use axum::{
extract::{Extension, Json, Query, UrlParams},
extract::{Extension, Json, Path, Query},
prelude::*,
response::IntoResponse,
service::ServiceExt,
@@ -129,7 +129,7 @@ struct UpdateTodo {
}
async fn todos_update(
UrlParams((id,)): UrlParams<(Uuid,)>,
Path(id): Path<Uuid>,
Json(input): Json<UpdateTodo>,
Extension(db): Extension<Db>,
) -> Result<impl IntoResponse, StatusCode> {
@@ -153,10 +153,7 @@ async fn todos_update(
Ok(response::Json(todo))
}
async fn todos_delete(
UrlParams((id,)): UrlParams<(Uuid,)>,
Extension(db): Extension<Db>,
) -> impl IntoResponse {
async fn todos_delete(Path(id): Path<Uuid>, Extension(db): Extension<Db>) -> impl IntoResponse {
if db.write().unwrap().remove(&id).is_some() {
StatusCode::NO_CONTENT
} else {