From e5e1b1a343b5d1c5582d39687d3c758ea717a374 Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Fri, 1 Nov 2019 00:23:19 +0100 Subject: [PATCH] ahem --- routes/products.pro | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 routes/products.pro diff --git a/routes/products.pro b/routes/products.pro new file mode 100644 index 0000000..03fcd8f --- /dev/null +++ b/routes/products.pro @@ -0,0 +1,19 @@ +:- http_handler( + root(products), + products_page, + [] +). + +% POST /products +products_page(Request) :- + member(method(post), Request), !, + http_read_data(Request, Json, []), + json_to_prolog(Json, product(Name, Price)), + assert_product(Name, Price), + reply_json(Json). + +% GET /products +products_page(_Request) :- + bagof(product(Name, Price), product(Name, Price), Products), + prolog_to_json(Products, Json), + reply_json(Json, []).