summaryrefslogtreecommitdiffstats
path: root/service-person/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'service-person/src/main.rs')
-rw-r--r--service-person/src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/service-person/src/main.rs b/service-person/src/main.rs
new file mode 100644
index 0000000..81be674
--- /dev/null
+++ b/service-person/src/main.rs
@@ -0,0 +1,52 @@
+use std::str::FromStr;
+
+use anyhow::Context;
+use actix_web::{web, App, HttpServer, HttpResponse, Result};
+use serde::Deserialize;
+
+#[derive(Debug, Deserialize)]
+struct Name(String);
+
+#[derive(Debug, Deserialize)]
+struct Age(usize);
+
+#[derive(Debug, Deserialize)]
+struct Address {
+ street: String,
+ number: String,
+ city: String,
+ country: String,
+}
+
+#[derive(Debug, Deserialize)]
+struct Person {
+ name: Name,
+ age: Age,
+ addr: Address,
+}
+
+async fn create_person(person: web::Json<Person>) -> Result<HttpResponse> {
+ log::debug!("Creating person = {:?}", person);
+ Ok(HttpResponse::Ok().finish())
+}
+
+
+#[actix_web::main]
+async fn main() -> anyhow::Result<()> {
+ env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
+ let bind = std::env::var("HOST").expect("environment: HOST variable not set");
+ let port = std::env::var("PORT")
+ .as_ref()
+ .map(|p| u16::from_str(p))
+ .expect("environment: PORT variable not set")
+ .context("Failed to parse port as integer")?;
+
+ HttpServer::new(|| {
+ App::new()
+ .route("/create", web::post().to(create_person))
+ })
+ .bind(format!("{}:{}", bind, port))?
+ .run()
+ .await
+ .map_err(anyhow::Error::from)
+}