Skip to content

Commit 161fb73

Browse files
committed
Respond with Location header on user creation
1 parent 8ee3217 commit 161fb73

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

backend/api/routes/v1/users.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The set of all users.
22
3-
use axum::http::StatusCode;
3+
use axum::http::{header, StatusCode};
44
use axum_macros::debug_handler;
55
use serde::{Deserialize, Serialize};
66
use sqlx::Acquire;
@@ -97,8 +97,11 @@ pub(crate) async fn post(Json(body): Json<PostRequest>) -> impl Response<PostRes
9797
})
9898
.await?;
9999

100-
// TODO: Set `Location` header.
101-
Ok((StatusCode::CREATED, Json(PostResponse { id: user_id })))
100+
Ok((
101+
StatusCode::CREATED,
102+
[(header::LOCATION, format!("/api/v1/users/{user_id}"))],
103+
Json(PostResponse { id: user_id }),
104+
))
102105
}
103106

104107
/// A `POST` response body for this API route.

0 commit comments

Comments
 (0)