From 514fa9d48f4e2f07e75285cacbc80b7fdf018a7f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 25 Sep 2023 15:54:07 +0200 Subject: [PATCH] healthcheck implemented --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/main.rs | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bfc9f6..9458aa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,6 +250,8 @@ name = "kosyncrs" version = "0.1.0" dependencies = [ "axum", + "serde", + "serde_json", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 496a9a7..9ce402b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,6 @@ edition = "2021" [dependencies] axum = "0.6.20" +serde = "1.0.188" +serde_json = "1.0.107" tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"] } diff --git a/src/main.rs b/src/main.rs index d0e65ff..9247678 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,17 @@ -use axum::{routing::get, Router}; +use axum::{http::StatusCode, routing::get, routing::post, routing::put, Json, Router}; + +use serde_json::{json, Value}; #[tokio::main] async fn main() { // build our application with a single route - let app = Router::new().route("/", get(|| async { "Hello, World!" })); + let app = Router::new() + .route("/", get(root)) + .route("/users/create", post(create_user)) + .route("/users/auth", get(auth_user)) + .route("/syncs/progress", put(update_progress)) + .route("/syncs/progress/:document", put(get_progress)) + .route("/healthcheck", get(healthcheck)); // run it with hyper on localhost:3000 axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) @@ -11,3 +19,19 @@ async fn main() { .await .unwrap(); } + +async fn root() -> &'static str { + "Hello, world!" +} + +async fn create_user() {} + +async fn auth_user() {} + +async fn update_progress() {} + +async fn get_progress() {} + +async fn healthcheck() -> (StatusCode, Json) { + (StatusCode::OK, Json(json!({ "state": "OK" }))) +}