/health_check with integration test implemented

This commit is contained in:
Andre Heber
2024-01-27 16:53:22 +01:00
commit b6679e2436
6 changed files with 1850 additions and 0 deletions

18
src/lib.rs Normal file
View File

@ -0,0 +1,18 @@
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use actix_web::dev::Server;
use std::net::TcpListener;
async fn health_check() -> HttpResponse {
HttpResponse::Ok().into()
}
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
let server = HttpServer::new(|| {
App::new()
.route("/health_check", web::get().to(health_check))
})
.listen(listener)?
.run();
Ok(server)
}

9
src/main.rs Normal file
View File

@ -0,0 +1,9 @@
use std::net::TcpListener;
use zero2prod::run;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let listener = TcpListener::bind("127.0.0.1:8000").expect("Failed to bind random port");
run(listener)?.await
}