[INITIAL] -> Did a basic API implementation

start with:
```cargo install cargo-watch && cargo watch -q -c -w src/ -x run```

---

this currently only returns "This is a Simple CRUD API";
This commit is contained in:
2025-07-29 20:14:41 +02:00
parent e42158ed0f
commit b568494757
6 changed files with 1717 additions and 0 deletions

1666
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "rsAPI"
version = "0.1.0"
edition = "2024"
[dependencies]
chrono = { version = "0.4.41", features = ["serde"] }
pretty_env_logger = "0.5.0"
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.47.0", features = ["full"] }
uuid = { version = "1.17.0", features = ["v4"] }
warp = "0.3.7"

0
src/handler.rs Normal file
View File

39
src/main.rs Normal file
View File

@@ -0,0 +1,39 @@
use std::env;
use serde::Serialize;
use warp::{reply::json, Filter, Rejection, Reply};
type WebResult<T> = std::result::Result<T, Rejection>;
#[derive(Serialize)]
pub struct GenericResponse {
pub status: String,
pub message: String,
}
pub async fn health_checker_handler() -> WebResult<impl Reply> {
const MESSAGE: &str = "This is a Simple CRUD API";
let jsonresponse = GenericResponse {
status: "success".to_string(),
message: MESSAGE.to_string(),
};
Ok(json(&jsonresponse))
}
#[tokio::main] // needed for async main
async fn main() {
pretty_env_logger::init();
let health_checker = warp::path!("api" / "healthchecker")
.and(warp::get())
.and_then(health_checker_handler); // don't call the function here!
let routes = health_checker.with(warp::log("api"));
println!("[LOG]: Server started successfully.");
// serve the server on localhost:8080
warp::serve(routes).run(([0, 0, 0, 0], 8080)).await;
}

0
src/model.rs Normal file
View File

0
src/response.rs Normal file
View File