Skip to content

Instantly share code, notes, and snippets.

@DefectingCat
Created December 26, 2023 01:15
Show Gist options
  • Save DefectingCat/e705e9a1f765540bb6693f055ab4a1f8 to your computer and use it in GitHub Desktop.
Save DefectingCat/e705e9a1f765540bb6693f055ab4a1f8 to your computer and use it in GitHub Desktop.
Axum fallback and hello world route
use axum::{
http::{StatusCode, Uri},
response::IntoResponse,
};
use tracing::info;
pub mod baidu;
pub async fn hello() -> &'static str {
"Hello World!"
}
/// Fallback route handler for handling unmatched routes.
///
/// This asynchronous function takes a `Uri` as an argument, representing the unmatched route.
/// It logs a message indicating that the specified route is not found and returns a standard
/// "Not Found" response with a `StatusCode` of `404`.
///
/// # Arguments
///
/// - `uri`: The `Uri` representing the unmatched route.
///
/// # Returns
///
/// Returns a tuple `(StatusCode, &str)` where `StatusCode` is set to `NOT_FOUND` (404),
/// indicating that the route was not found, and the string "Not found" as the response body.
pub async fn fallback(uri: Uri) -> impl IntoResponse {
info!("route {} not found", uri);
(StatusCode::NOT_FOUND, "Not found")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment