Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Last active March 5, 2023 16:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsodmike/77bcba5914d8195c7efdda64d2621880 to your computer and use it in GitHub Desktop.
Save bsodmike/77bcba5914d8195c7efdda64d2621880 to your computer and use it in GitHub Desktop.
Axum Redirect is syntactic sugar for a Response
async fn accept_form(Form(input): Form<Input>, state: Extension<AppState>) -> Response<Body> {
dbg!(&input);
match save_form(&input, &state).await {
Ok(_) => (),
Err(e) => tracing::error!("Failed: {:?}", e),
}
let mut response = Response::builder()
.status(StatusCode::SEE_OTHER)
.body(Body::empty())
.unwrap();
let headers = response.headers_mut();
headers.insert(LOCATION, "/".parse().unwrap());
response
}
// Simpler syntax
async fn accept_form(Form(input): Form<Input>, state: Extension<AppState>) -> Redirect {
dbg!(&input);
match save_form(&input, &state).await {
Ok(_) => (),
Err(e) => tracing::error!("Failed: {:?}", e),
}
Redirect::to("/".parse().unwrap())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment