ahem
This commit is contained in:
parent
8d0b13a303
commit
e5e1b1a343
1 changed files with 19 additions and 0 deletions
19
routes/products.pro
Normal file
19
routes/products.pro
Normal file
|
@ -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, []).
|
Loading…
Reference in a new issue