prolog-point-of-sale/routes/products.pl

15 lines
435 B
Perl
Raw Permalink Normal View History

2019-11-03 01:05:33 +00:00
:- http_handler(root(api/products), products_page, []).
2019-10-31 23:23:19 +00:00
% 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),
2019-11-03 01:05:33 +00:00
reply_prolog(product(Name, Price)).
2019-10-31 23:23:19 +00:00
% GET /products
products_page(_Request) :-
bagof(product(Name, Price), product(Name, Price), Products),
2019-11-03 01:05:33 +00:00
reply_prolog(Products).