I'm creating a program in Prolog using a HTTP server to make requests...
I'm want to encapsulate the code in a way I can reuse it and have the http stuff in one module, my "controller" to handle requests in another module, etc.
I started having problems with the http dispatch handler registration:
:- http_handler('/test', foobar, []).
Is it possible to have something like this:
register_handler(path, callback) :-
http_handler(path, callback, []).
I tried using that but I got a error must likely due to the "callback" parameter. Also, the callback predicate is defined in a different module so I used:
:-consult(api_controller).
[EDIT]
server.pl
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/http_json)).
:- use_module(api_controller).
:- http_handler('/test', foo, []).
server(Port):-http_server(http_dispatch, [port(Port)]).
api_controller.pl
foo(_request) :-
format('Content-type: text/plain~n~n'),
format('Hello world!~n').
Error:
http_dispatch:call_action/2: Undefined procedure: foo/1