use actix_web::{web, HttpResponse};
use kegani::prelude::*;
#[derive(Clone)]
struct AppState {
pub name: String,
}
#[get("/api/hello")]
async fn hello() -> &'static str {
"Hello from Kegani!"
}
#[post("/api/echo")]
async fn echo(body: String) -> HttpResponse {
HttpResponse::Ok()
.content_type("application/json")
.body(body)
}
#[get("/api/users/{id}")]
async fn get_user(Path(id): Path<String>) -> HttpResponse {
let user = serde_json::json!({
"id": id,
"name": format!("User {}", id),
"email": format!("user{}@example.com", id)
});
HttpResponse::Ok()
.content_type("application/json")
.json(user)
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
tracing::info!("Starting Kegani server...");
tracing::info!("📚 API Docs: http://127.0.0.1:30080/swagger-ui");
tracing::info!("📖 ReDoc: http://127.0.0.1:30080/redoc");
App::new()
.host("127.0.0.1")
.port(30080)
.run()
.await
}