feat: subscribe API route skeleton

- Added `serde` crate for serialisation or deserialisation of data
- Added test cases for the `subscribe` API route
- Refactor the testing setup to another module `test_utils`
- use random TCP port for testing
This commit is contained in:
2024-04-22 17:00:55 -04:00
parent 4b4286ae43
commit 84fc74a0d1
8 changed files with 115 additions and 29 deletions

View File

@@ -1,15 +1,26 @@
use actix_web::{web, App, HttpResponse, HttpServer};
use actix_web::dev::Server;
use actix_web::{web, App, HttpResponse, HttpServer};
use std::net::TcpListener;
async fn healthcheck_route() -> HttpResponse {
return HttpResponse::Ok().finish()
#[derive(serde::Deserialize)]
struct FormData {
email: String,
name: String,
}
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error>{
let server = HttpServer::new(||{
async fn healthcheck_route() -> HttpResponse {
HttpResponse::Ok().finish()
}
async fn subscribe_route(_form: web::Form<FormData>) -> HttpResponse {
HttpResponse::Ok().finish()
}
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
let server = HttpServer::new(|| {
App::new()
.route("/health_check", web::get().to(healthcheck_route))
.route("/health_check", web::get().to(healthcheck_route))
.route("/subscribe", web::post().to(subscribe_route))
})
.listen(listener)?
.run();