Update http_server.pl

Avoid overwriting of predicate and made explicit reference to the loading of library(http/http_server).
This commit is contained in:
matteob8
2025-04-21 19:13:20 +02:00
committed by GitHub
parent d18ef52e67
commit d79bc199b3

View File

@@ -17,6 +17,8 @@ as one HTTP method (in lowercase) and followed by a Route Match and a predicate
which will handle the call.
```
:- use_module(library(http/http_server)).
text_handler(Request, Response) :-
http_status_code(Response, 200),
http_body(Response, text("Welcome to Scryer Prolog!")).
@@ -24,10 +26,11 @@ text_handler(Request, Response) :-
parameter_handler(User, Request, Response) :-
http_body(Response, text(User)).
http_listen(7890, [
get(echo, text_handler), % GET /echo
post(user/User, parameter_handler(User)) % POST /user/<User>
]).
top:-
http_listen(7890, [
get(echo, text_handler), % GET /echo
post(user/User, parameter_handler(User)) % POST /user/<User>
]).
```
Every handler predicate will have at least 2-arity, with Request and Response.