summaryrefslogtreecommitdiff
path: root/dichroism/src
diff options
context:
space:
mode:
authorAdam Carpenter <atc@53hor.net>2020-05-05 14:09:14 -0400
committerAdam Carpenter <atc@53hor.net>2020-05-05 14:09:14 -0400
commit8b5bb367e2bd03a64c233e1eb128c2d0980f5b01 (patch)
tree2a86eccf3caeca68519e8a76d04710ad76ecce95 /dichroism/src
parentb5960dffbd7151c2eedc0e897f94f7b1691c2a39 (diff)
downloadtheglassyladies-8b5bb367e2bd03a64c233e1eb128c2d0980f5b01.tar.xz
theglassyladies-8b5bb367e2bd03a64c233e1eb128c2d0980f5b01.zip
updated debug script, moved backlog to Deck
Diffstat (limited to 'dichroism/src')
-rw-r--r--dichroism/src/main.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/dichroism/src/main.rs b/dichroism/src/main.rs
index e4bb217..858a21c 100644
--- a/dichroism/src/main.rs
+++ b/dichroism/src/main.rs
@@ -1,12 +1,48 @@
-use actix_web::{web, App, HttpRequest, HttpServer, Responder};
+use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder};
+use futures::future::{ready, Ready};
use listenfd::ListenFd;
+use serde::Serialize;
+
+#[derive(Serialize)]
+struct Product {
+ id: u32,
+ name: String,
+ quantity: i32,
+ cents: u32,
+ img_path: String,
+ description: String,
+}
+
+impl Responder for Product {
+ type Error = Error;
+ type Future = Ready<Result<HttpResponse, Error>>;
+
+ fn respond_to(self, _req: &HttpRequest) -> Self::Future {
+ let body = serde_json::to_string(&self).unwrap();
+
+ ready(Ok(HttpResponse::Ok()
+ .content_type("application/json")
+ .body(body)))
+ }
+}
+
+async fn products() -> impl Responder {
+ Product {
+ id: 1,
+ name: "Beach Box".to_string(),
+ quantity: 3,
+ cents: 1100,
+ img_path: "/beach_box.jpg".to_string(),
+ description: "It's a beach in a box".to_string(),
+ }
+}
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
-async fn index(_: HttpRequest) -> impl Responder {
+async fn index() -> impl Responder {
"Hello, this is an API. If you're looking for the web app, try port 443.".to_string()
}
@@ -17,6 +53,7 @@ async fn main() -> std::io::Result<()> {
App::new()
.route("/", web::get().to(index))
.route("/{name}", web::get().to(greet))
+ .route("/products", web::get().to(products))
});
server = if let Some(l) = listenfd.take_tcp_listener(0).unwrap() {