-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use axum::response::IntoResponse; | ||
use axum::{http::StatusCode, response::Json}; | ||
use serde_json::Value; | ||
use std::collections::HashMap; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
// Default handler for no YAML configuration | ||
pub async fn default_handler() -> &'static str { | ||
"OK" | ||
} | ||
|
||
// Handler for custom route | ||
pub async fn handle_custom_route( | ||
data: Arc<Value>, | ||
status: StatusCode, | ||
headers: Arc<HashMap<String, String>>, | ||
) -> impl axum::response::IntoResponse { | ||
let mut response = axum::response::Response::new(Json(data.as_ref().clone()).into_response()); | ||
*response.status_mut() = status; | ||
|
||
for (key, value) in headers.as_ref() { | ||
response.headers_mut().insert( | ||
axum::http::header::HeaderName::from_str(key).unwrap(), | ||
axum::http::header::HeaderValue::from_str(value).unwrap(), | ||
); | ||
} | ||
|
||
response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[macro_export] | ||
macro_rules! route_with_method { | ||
($app:expr, $method:expr, $endpoint:expr, $handler:expr) => { | ||
match $method { | ||
$crate::structs::HttpMethod::Get => $app.route($endpoint, axum::routing::get($handler)), | ||
$crate::structs::HttpMethod::Post => { | ||
$app.route($endpoint, axum::routing::post($handler)) | ||
} | ||
$crate::structs::HttpMethod::Put => $app.route($endpoint, axum::routing::put($handler)), | ||
$crate::structs::HttpMethod::Patch => { | ||
$app.route($endpoint, axum::routing::patch($handler)) | ||
} | ||
$crate::structs::HttpMethod::Delete => { | ||
$app.route($endpoint, axum::routing::delete($handler)) | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters