1:- module(bc_api_io, [
2 bc_reply_success/1, 3 bc_reply_error/1, 4 bc_read_by_schema/2 5]). 6
7:- use_module(library(http/http_json)). 8:- use_module(library(http/http_wrapper)). 9:- use_module(library(dict_schema)).
18bc_read_by_schema(Schema, Dict):-
19 http_current_request(Request),
20 http_read_json_dict(Request, Raw),
21 convert(Raw, Schema, Dict, Errors),
22 ( Errors = []
23 ; throw(error(invalid_input(Errors)))), !.
30bc_reply_success(Data):-
31 write('Cache-Control: no-cache\r\n'),
32 reply_json(_{ status: success, data: Data }).
38bc_reply_error(Message):-
39 write('Cache-Control: no-cache\r\n'),
40 reply_json(_{ status: error, message: Message })