summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/lib.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-10-31 15:14:36 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-10-31 15:14:36 -0700
commit10a90a353a3bb46652a42b0e01834fd158fd600d (patch)
treea325906cfc31e54187f98cdde6f7936f20ea539e /adenosine-pds/src/lib.rs
parentba8f10afd51a6f629291abdcfe25a70b7b517f1c (diff)
downloadadenosine-10a90a353a3bb46652a42b0e01834fd158fd600d.tar.gz
adenosine-10a90a353a3bb46652a42b0e01834fd158fd600d.zip
PDS: early progress
Diffstat (limited to 'adenosine-pds/src/lib.rs')
-rw-r--r--adenosine-pds/src/lib.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
new file mode 100644
index 0000000..bb34c80
--- /dev/null
+++ b/adenosine-pds/src/lib.rs
@@ -0,0 +1,42 @@
+
+use anyhow::Result;
+use log::{self, debug};
+use warp::Filter;
+use warp::reply::Response;
+use std::collections::HashMap;
+
+pub async fn run_server() -> Result<()> {
+
+ // GET /
+ let homepage = warp::path::end().map(|| "Not much to see here yet!");
+
+ // GET /xrpc/some.method w/ query params
+ let xrpc_some_get = warp::get()
+ .and(warp::path!("xrpc" / "some.method"))
+ .and(warp::query::<HashMap<String, String>>())
+ .map(|query_params: HashMap<String, String>| {
+ println!("query params: {:?}", query_params);
+ // return query params as a JSON map object
+ warp::reply::json(&query_params)
+ });
+
+ // POST /xrpc/other.method w/ query params
+ let xrpc_other_post = warp::post()
+ .and(warp::path!("xrpc" / "other.method"))
+ .and(warp::query::<HashMap<String, String>>())
+ .and(warp::body::json())
+ .map(|query_params: HashMap<String, String>, body_val: serde_json::Value| {
+ println!("query params: {:?}", query_params);
+ println!("body JSON: {}", body_val);
+ // echo it back
+ warp::reply::json(&body_val)
+ });
+
+ let routes = homepage.or(xrpc_some_get).or(xrpc_other_post).with(warp::log("adenosine-pds"));
+ warp::serve(routes)
+ .run(([127, 0, 0, 1], 3030))
+ .await;
+ Ok(())
+}
+
+// TODO: tokio::task::spawn_blocking