%% swipl -s server.pl --quiet -g "server('127.0.0.1':8082)"
%% curl -i -X GET http://localhost:8082/

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_json)).

:- http_handler(/, handle, []).

server(Port) :-
   http_server(http_dispatch,[port(Port)]),
   format(user_output,"Started server on port ~p.~n",[Port]).

handle(_Request) :-
   Term = a(b([c,d]),e(f)),
   with_output_to(string(String),
      print_term(Term, [indent_arguments(2),tab_width(0)])),
   reply_json_dict(_{ term: String }).
