File "spin"
This Prolog text provides a HTTP client in the form of open/4
predicate. The predicates http_server_new/1, http_server_on/4 and
http_server_listen/2 provide a HTTP server configuration and
start-up. The End-users can realize their own dispatch mechanism
by means of the predicates http_current_method/2,
http_current_path/2 and url_search_params/3.
Currently we only support text content and no binary content yet.
The end-user can deliver content via the predicates write_head/3
and http_text_new/2. Calling flush_output/1 on the text writer is
permitted and will complete a chunk and send it to request client.
To indicate the end of a response it is mandatory to call close/1
on the text writer.
The following spin predicates are provided:
- http_server_new(S):
- The predicate succeeds in S with a new http server.
- http_server_on(S, L, Q, G) :
- The predicate succeeds. As a side effect it adds a type T
event handler with formal parameter list L and callback goal G
to the HTTP server S. Currently supported event type on all
targets:
- request: Parameter list [P, Q] where P is request and Q is
response.
- http_server_listen(S, P):
- The predicate succeeds. As a side effect the server S starts
listening on port P.
- http_server_close(S):
- The predicate succeeds. As a side effect the server S is
closed.
- http_current_method(S, P):
- The predicate succeeds in M with the method of the HTTP
request S.
- http_current_path(S, P):
- The predicate succeeds in P with the path of the HTTP request
S.
- http_current_headers(S, M):
- The predicate succeeds in M with the headers of the HTTP
request S.
- http_input_new(S, R):
- http_input_new(S, R, O):
- The predicate succeeds in R with a new text reader for the
HTTP request S. The ternary predicate allows specifying text
reader options.
- url_search_params(U, P, L)
- The predicate succeeds in P with the non-query part of U and
in L with the query part of U decoded into a key-value list.
- http_write_head(S, C, H):
- The predicate succeeds. As a side effect it writes the status
code C and the headers map H to the HTTP response S.
- http_output_new(S, W):
- http_output_new(S, W, O):
- The predicate succeeds in W with a new text writer for the
HTTP response S. The ternary predicate allows specifying text
writer options.
Kommentare