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,6 +26,7 @@ text_handler(Request, Response) :-
parameter_handler(User, Request, Response) :- parameter_handler(User, Request, Response) :-
http_body(Response, text(User)). http_body(Response, text(User)).
run:-
http_listen(7890, [ http_listen(7890, [
get(echo, text_handler), % GET /echo get(echo, text_handler), % GET /echo
post(user/User, parameter_handler(User)) % POST /user/<User> post(user/User, parameter_handler(User)) % POST /user/<User>