Skip to content

calling from other languages #1931

Answered by david-sitsky
mvolkmann asked this question in Q&A
Discussion options

You must be logged in to vote

I think what you want is this:

:- use_module(library(http/http_server)).

text_handler(_, Response) :-
  http_status_code(Response, 200),
  http_body(Response, text("Welcome to Scryer Prolog!")).

initialization :-
  % GET /echo
  http_listen(8081, [
    get(echo, text_handler)
  ]).

Then from the prompt, do the following:

?- initialization.
Listening at 0.0.0.0:8081

Sure enough, visiting http://localhost:8081/echo works and I see the "Welcome to Scryer Prolog!" text. However the prompt shows an error soon after. The browser (chrome) seem to request favicon.ico which presumably also needs a handler?

?- initialization.
Listening at 0.0.0.0:8081
2023-07-31 (16:49:09) get /echo
2023-07-31 (…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@triska
Comment options

@mvolkmann
Comment options

@david-sitsky
Comment options

Answer selected by mvolkmann
@mvolkmann
Comment options

@triska
Comment options

Comment options

You must be logged in to vote
1 reply
@triska
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants