Skip to content

Instantly share code, notes, and snippets.

@rla
Last active May 31, 2018 11:35
Show Gist options
  • Save rla/b448a07d567bcc69650566a23b23c668 to your computer and use it in GitHub Desktop.
Save rla/b448a07d567bcc69650566a23b23c668 to your computer and use it in GitHub Desktop.
Arouter http_daemon
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_unix_daemon)).
:- use_module(prolog/arouter).
:- route_get(hello/Name, handle_hello(Name)).
handle_hello(Name):-
format('Content-Type: text/plain; charset=UTF-8~n~n'),
format('Hello ~w', [Name]).
http_unix_daemon:http_server_hook(Options):-
http_server(handle_request, Options).
handle_request(Request):-
( aroute(Request)
-> true
; http_dispatch(Request)).
:- initialization(http_daemon, main).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment