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

14 lines
435 B
Prolog

:- http_handler(root(api/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_prolog(product(Name, Price)).
% GET /products
products_page(_Request) :-
bagof(product(Name, Price), product(Name, Price), Products),
reply_prolog(Products).