You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
989 B
46 lines
989 B
use axum::{ |
|
Json, Router, |
|
extract::State, |
|
routing::{get, post}, |
|
}; |
|
use chrono::Utc; |
|
use serde::Serialize; |
|
use serde_json::Value; |
|
use std::sync::Arc; |
|
|
|
use crate::state::AppState; |
|
|
|
#[derive(Debug, Serialize)] |
|
pub struct EchoResponse { |
|
pub data: Value, |
|
pub timestamp: String, |
|
} |
|
|
|
#[derive(Debug, Serialize)] |
|
pub struct VersionResponse { |
|
pub name: String, |
|
pub version: String, |
|
} |
|
|
|
pub async fn echo_handler( |
|
State(_state): State<Arc<AppState>>, |
|
Json(payload): Json<Value>, |
|
) -> Json<EchoResponse> { |
|
Json(EchoResponse { |
|
data: payload, |
|
timestamp: Utc::now().to_rfc3339(), |
|
}) |
|
} |
|
|
|
pub async fn version_handler(State(state): State<Arc<AppState>>) -> Json<VersionResponse> { |
|
Json(VersionResponse { |
|
name: state.name.clone(), |
|
version: state.version.clone(), |
|
}) |
|
} |
|
|
|
pub fn routes() -> Router<Arc<AppState>> { |
|
Router::new() |
|
.route("/echo", post(echo_handler)) |
|
.route("/version", get(version_handler)) |
|
}
|
|
|