UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

23 lines 10.8 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>HTTP server &mdash; The Ciao System v1.22</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="http_doc.html">&#x2191;</a><a class="lpdoc-navbutton" href="http_client.html">&#x2190;</a><a class="lpdoc-navbutton" href="url.html">&#x2192;</a><a class="lpdoc-navbutton" href="ciaosearch.html">&#x1F50D;</a></span><span><a href="ciaofulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciao.html">The Ciao System</a> &raquo;<br/> </li><li><a href="ExtraLibs.html">PART VIII - Additional libraries</a> &raquo;<br/> </li><li><a href="http_doc.html">HTTP client/server libraries</a> &raquo;<br/> </li><li><a href=""><strong>HTTP server</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Usage and interface">Usage and interface</a></li><li><a href="#Documentation on exports">Documentation on exports</a></li><li><a href="#Documentation on multifiles">Documentation on multifiles</a></li><li><a href="#Documentation on imports">Documentation on imports</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>HTTP server</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#http_server"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="The Ciao Development Team" href="ciaosearch.html#The Ciao Development Team">The Ciao Development Team</a>, <a class="lpdoc-idx-anchor" id="Jose F. Morales" href="ciaosearch.html#Jose F. Morales">Jose F. Morales (multifile-based HTTP simple server)</a>.<p> <p>This module implements a simple HTTP server.<p>It can be used to handle individual HTTP requests (<a class="lpdoc-idx-anchor" id="0" href="#http_serve_fetch/2"><tt>http_serve_fetch/2</tt></a>) or for implementing a simple HTTP server (see <a class="lpdoc-idx-anchor" id="1" href="#http_bind/1"><tt>http_bind/1</tt></a>, <a class="lpdoc-idx-anchor" id="2" href="#http_loop/1"><tt>http_loop/1</tt></a>, <a class="lpdoc-idx-anchor" id="3" href="#http_shutdown/1"><tt>http_shutdown/1</tt></a>).<p>Clients of this module must use the <a class="lpdoc-idx-anchor" id="4" href="ciaosearch.html#http_server_hooks"><tt>http_server_hooks</tt></a> package and implement the multifile <a class="lpdoc-idx-anchor" id="5" href="#httpserv.handle/3"><tt>httpserv.handle/3</tt></a> (see <a class="lpdoc-idx-anchor" id="6" href="#http_loop/1"><tt>http_loop/1</tt></a> for details).<br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_module(library(http/http_server)).</tt><li><strong>Exports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Predicates:</em><br/><a class="lpdoc-idx-anchor" id="7" href="#http_serve_fetch/2"><tt>http_serve_fetch/2</tt></a>, <a class="lpdoc-idx-anchor" id="8" href="#http_bind/1"><tt>http_bind/1</tt></a>, <a class="lpdoc-idx-anchor" id="9" href="#http_loop/1"><tt>http_loop/1</tt></a>, <a class="lpdoc-idx-anchor" id="10" href="#http_shutdown/1"><tt>http_shutdown/1</tt></a>, <a class="lpdoc-idx-anchor" id="11" href="#http_protect/4"><tt>http_protect/4</tt></a>. <li><em>Multifiles:</em><br/><a class="lpdoc-idx-anchor" id="12" href="#httpserv.handle/3"><tt>httpserv.handle/3</tt></a>, <a class="lpdoc-idx-anchor" id="13" href="#httpserv.file_path/2"><tt>httpserv.file_path/2</tt></a>. </ul></ul></div></div><div id="Documentation on exports"><h2>Documentation on exports</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="http_serve_fetch/2" href="ciaosearch.html#http_serve_fetch/2">http_serve_fetch/2</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>http_serve_fetch(Stream,Serve)</tt> </span><p>Read a HTTP request from <span class="lpdoc-var">Stream</span>, obtain the response calling <span class="lpdoc-var">Serve</span> predicate, and write the response to the socket stream.</p><ul class="lpdoc-itemize-minus"></ul> <em>Meta-predicate</em> with arguments: <tt>http_serve_fetch(?,pred(2))</tt>.<br/></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="http_bind/1" href="ciaosearch.html#http_bind/1">http_bind/1</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>http_bind(Port)</tt> </span><p>Bind socket to the port <span class="lpdoc-var">Port</span> (use with <a class="lpdoc-idx-anchor" id="14" href="#http_loop/1"><tt>http_loop/1</tt></a>)</p><ul class="lpdoc-itemize-minus"></ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="http_loop/1" href="ciaosearch.html#http_loop/1">http_loop/1</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>http_loop(ExitCode)</tt> </span><p>Listen and handle HTTP requests in a loop. You can terminate this loop by <a class="lpdoc-idx-anchor" id="15" href="#http_shutdown/1"><tt>http_shutdown/1</tt></a> predicate. Requests are handled by multifile <a class="lpdoc-idx-anchor" id="16" href="#httpserv.handle/3"><tt>httpserv.handle/3</tt></a> and <a class="lpdoc-idx-anchor" id="17" href="#httpserv.file_path/2"><tt>httpserv.file_path/2</tt></a> predicates (declared in <a class="lpdoc-idx-anchor" id="18" href="ciaosearch.html#http_server_hooks"><tt>http_server_hooks</tt></a> file).</p><ul class="lpdoc-itemize-minus"></ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="http_shutdown/1" href="ciaosearch.html#http_shutdown/1">http_shutdown/1</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>http_shutdown(ExitCode)</tt> </span><p><span class="lpdoc-var">ExitCode</span> mark that we are not going to process further requests</p><ul class="lpdoc-itemize-minus"></ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="http_protect/4" href="ciaosearch.html#http_protect/4">http_protect/4</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>http_protect(Handler,ErrHandler,Request,Response)</tt> </span><p>Execute <span class="lpdoc-var">Handler</span> on <span class="lpdoc-var">Request</span> to obtain <span class="lpdoc-var">Response</span>. If <span class="lpdoc-var">Handler</span> fails or raises some exception <span class="lpdoc-var">E</span>, a response is obtained calling <span class="lpdoc-var">ErrHandler</span> on <span class="lpdoc-var">E</span>. This is useful, for example, to produce an HTML page informing about the incident</p><ul class="lpdoc-itemize-minus"></ul> <em>Meta-predicate</em> with arguments: <tt>http_protect(pred(2),pred(2),?,?)</tt>.<br/></div></div><p> </div><div id="Documentation on multifiles"><h2>Documentation on multifiles</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="httpserv.handle/3" href="ciaosearch.html#httpserv.handle/3">httpserv.handle/3</a></div><div class="lpdoc-deftext">No further documentation available for this predicate. The predicate is <em>multifile</em>.<br/></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="httpserv.file_path/2" href="ciaosearch.html#httpserv.file_path/2">httpserv.file_path/2</a></div><div class="lpdoc-deftext">No further documentation available for this predicate. The predicate is <em>multifile</em>.<br/></div></div><p> </div><div id="Documentation on imports"><h2>Documentation on imports</h2>This module has the following direct dependencies:<ul class="lpdoc-itemize-minus"><li><em>System library modules:</em><br/><a class="lpdoc-idx-anchor" id="19" href="datafacts_rt.html"><tt>datafacts_rt</tt></a>, <a class="lpdoc-idx-anchor" id="20" href="lists.html"><tt>lists</tt></a>, <a class="lpdoc-idx-anchor" id="21" href="port_reify.html"><tt>port_reify</tt></a>, <a class="lpdoc-idx-anchor" id="22" href="pathnames.html"><tt>pathnames</tt></a>, <a class="lpdoc-idx-anchor" id="23" href="http_messages.html"><tt>http_messages</tt></a>, <a class="lpdoc-idx-anchor" id="24" href="sockets.html"><tt>sockets</tt></a>, <a class="lpdoc-idx-anchor" id="25" href="stream_utils.html"><tt>stream_utils</tt></a>, <a class="lpdoc-idx-anchor" id="26" href="sockets_io.html"><tt>sockets_io</tt></a>, <a class="lpdoc-idx-anchor" id="27" href="system.html"><tt>system</tt></a>, <a class="lpdoc-idx-anchor" id="28" href="terms.html"><tt>terms</tt></a>, <a class="lpdoc-idx-anchor" id="29" href="ciaosearch.html#mimetypes"><tt>mimetypes</tt></a>, <a class="lpdoc-idx-anchor" id="30" href="write.html"><tt>write</tt></a>, <a class="lpdoc-idx-anchor" id="31" href="format.html"><tt>format</tt></a>, <a class="lpdoc-idx-anchor" id="32" href="http_date.html"><tt>http_date</tt></a>. <li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="33" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="34" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="35" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="36" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="37" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>, <a class="lpdoc-idx-anchor" id="38" href="isomodes_doc.html"><tt>isomodes</tt></a>, <a class="lpdoc-idx-anchor" id="39" href="dcg_doc.html"><tt>dcg</tt></a>, <a class="lpdoc-idx-anchor" id="40" href="ciaosearch.html#hiord"><tt>hiord</tt></a>, <a class="lpdoc-idx-anchor" id="41" href="doccomments_doc.html"><tt>doccomments</tt></a>, <a class="lpdoc-idx-anchor" id="42" href="datafacts_doc.html"><tt>datafacts</tt></a>. </ul></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>