aboutsummaryrefslogtreecommitdiff
path: root/src/bin/web.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/web.rs')
-rw-r--r--src/bin/web.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/bin/web.rs b/src/bin/web.rs
index 243e4a2..cc6b94f 100644
--- a/src/bin/web.rs
+++ b/src/bin/web.rs
@@ -1,7 +1,9 @@
+use hiccup::{SimUpdates, Simulation};
+use serde::Deserialize;
use std::fs;
use axum::{
- response::Html,
+ response::{Html, Json},
routing::get,
Router,
};
@@ -10,10 +12,26 @@ async fn root_get() -> Html<String> {
Html(fs::read_to_string("front/index.html").unwrap())
}
+#[derive(Deserialize)]
+struct SimSpecs {
+ principal: f64,
+ i1: f64,
+ years: u32,
+}
+
+async fn api_simulate_get<'a>(Json(specs): Json<SimSpecs>) -> Json<hiccup::Simulation<'a>> {
+ let mut sim = Simulation::new(specs.principal, specs.i1, specs.years);
+ let updates: SimUpdates = SimUpdates::default();
+ sim.run(updates);
+ Json(sim)
+}
+
#[tokio::main]
async fn main() {
// build our application with a single route
- let app = Router::new().route("/", get(root_get));
+ let app = Router::new()
+ .route("/", get(root_get))
+ .route("/api/simulate", get(api_simulate_get));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();