Skip to content

Instantly share code, notes, and snippets.

@kaiser185
Created August 18, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaiser185/254675d01c7227569d95ca9cfa1f92ad to your computer and use it in GitHub Desktop.
Save kaiser185/254675d01c7227569d95ca9cfa1f92ad to your computer and use it in GitHub Desktop.
Logtalk Http Server
:- http_dispatch:http_handler(/, user:say_hi, []).
:- http_dispatch:http_handler(root(sam), user:say_hi_sam, []). %root(sam) -> GET -> <addr>/sam
say_hi(_Request) :- % (3)
http_server::say_hi(_Request).
say_hi_sam(_Request) :-
http_server::say_hi_sam(_Request).
:- object(http_server).
:- public(run/0).
run :-
{ thread_httpd:http_server(
http_dispatch:http_dispatch,
[port(8080)]) }.
:- public(say_hi/1).
say_hi(_Request) :- % (3)
format('Content-type: text/plain~n~n'),
format('Screw the World!~n').
:- public(say_hi_sam/1).
say_hi_sam(_Request) :- % (3)
format('Content-type: text/plain~n~n'),
format('Hello Sam!~n').
:- end_object.
:- use_module(library(http/thread_httpd), []).
:- use_module(library(http/http_dispatch), []).
:- initialization((
logtalk_load(http_server)
)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment