catch(info_profile(Key,Type,Dict),_,throw(http_reply(server_error("The information associated with this UUID appears to be missing.")))),
(http_read_json_dict(Request,NewDict)
;
throw(http_reply(bad_request("No content type info: should be 'application/json'.")))
),
(retract(info_profile(Key,Type,Dict)),
assert(info_profile(Key,Type,NewDict))
;
throw(http_reply(server_error("Unable to modify knowledge base!")))
),
dict_create(Reply,_,[identifier(Key)]),
reply_json_dict(Reply).
profile_handler(Key,Request):-
% If a GET request is received...
memberchk(method(get),Request),!,
catch(info_profile(Key,_,Dict),_,throw(http_reply(server_error("The information associated with this UUID appears to be missing.")))),
reply_json_dict(Dict).
profile_handler(Key,Request):-
% If a DELETE request is received...
memberchk(method(delete),Request),!,
catch(info_profile(Key,Type,Dict),_,throw(http_reply(server_error("The information associated with this UUID appears to be missing.")))),
(retract(info_profile(Key,Type,Dict))
;
throw(http_reply(not_modified("Unable to modify knowledge base!")))
),
atom_concat('profiles/',Key,Location),
http_delete_handler(root(Location)),
format('Content-type: text/plain~n~n'),
format('The information profile with UUID ~q has been deleted.',[Key]).
profile_handler(Key,Request):-
% If a POST request is received...
member(method(post),Request),!,
format('Status: 409~n'),
format('Content-type: text/plain~n~n'),
format('Profile with UUID ~q already exists (use PUT to update an existing profile, or POST to ./profiles to generate a new profile with a new UUID).',[Key]).
profile_handler(_,_):-
% Otherwise report an error.
format('Status: 403~n'),
format('Content-type: text/plain~n~n'),
format('This request is not permitted for the URL given.').
% info_type(?Type, +Dict)---determines if a given profile is of a given type.