Merge pull request #2901 from matteob8/patch-1

Update http_server.pl
This commit is contained in:
Mark Thom
2025-04-29 21:41:07 -07:00
committed by GitHub

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. which will handle the call.
``` ```
:- use_module(library(http/http_server)).
text_handler(Request, Response) :- text_handler(Request, Response) :-
http_status_code(Response, 200), http_status_code(Response, 200),
http_body(Response, text("Welcome to Scryer Prolog!")). http_body(Response, text("Welcome to Scryer Prolog!")).
@@ -24,10 +26,11 @@ text_handler(Request, Response) :-
parameter_handler(User, Request, Response) :- parameter_handler(User, Request, Response) :-
http_body(Response, text(User)). http_body(Response, text(User)).
http_listen(7890, [ run:-
get(echo, text_handler), % GET /echo http_listen(7890, [
post(user/User, parameter_handler(User)) % POST /user/<User> 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. Every handler predicate will have at least 2-arity, with Request and Response.