Updates.
h3rald h3rald@h3rald.com
Mon, 13 Jan 2020 12:47:02 +0000
2 files changed,
40 insertions(+),
30 deletions(-)
M
assets/min/Min_DeveloperGuide.htm
→
assets/min/Min_DeveloperGuide.htm
@@ -9334,12 +9334,12 @@ <p>Performs an HTTP request.</p>
<div class="sidebar"><p>Example</p> -<p>The following code constructs a <span class="kwd">request</span> dictionary using the <strong>tap</strong> operator and passes it to the <strong>request</strong> operator to perform an HTTP GET request to <a href="http://httpbin.org/ip">http://httpbin.org/ip</a>:</p> +<p>The following code constructs a <span class="kwd">request</span> dictionary and passes it to the <strong>request</strong> operator to perform an HTTP GET request to <a href="http://httpbin.org/ip">http://httpbin.org/ip</a>:</p> -<pre><code>{} ( - ("GET" %method) - ("http://httpbin.org/ip" %url) -) tap request +<pre><code>{} + "GET" %method) + "http://httpbin.org/ip" %url +request </code></pre></div></div> <p><a id="min-operator-id-start-server"></a>@@ -9364,32 +9364,42 @@ <div class="sidebar"><p>Example</p>
<p>The following program starts a very simple HTTP server that can display the current timestamp or date and time in ISO 8601 format:</p> -<pre><code>( - :req - req /url :url - ;Set response body - "Invalid Request: $1" (url) => % :body - ("/datetime" url ==) ( - timestamp datetime @body - ) when - ("/timestamp" url ==) ( - timestamp string @body - ) when - ("/shutdown" url ==) ( - "Stopping server..." puts! - stop-server - ) when - ;Prepare response - {} body %body -) =handler +<pre><code>; Define the request handler +( + ; Assume there is a request on the stack, take it off and give it the name req + :req + ; Let's see what we got (print req to standard out) + "THE REQUEST:" puts! req puts! + ; The request is a dictionary, we retrieve the value for the key url, and give it the name url + req /url :url + "THE URL is '$1'." url quote % puts! + ; Constuct response body + ( + (("/datetime" url ==) (timestamp datetime)) + (("/timestamp" url ==) (timestamp string)) + (("/shutdown" url ==) ("Stopping server..." puts! stop-server)) + (("/" url ==) ( + ; this is a bit short, but works with Chrome, IE, Edge, Safari + "<a href='/datetime'>datetime</a>, <a href='/timestamp'>timestamp</a>, <a href='/shutdown'>stop</a>" + )) + ((true) ("Invalid Request: $1" url quote %)) + ) case + :body + ; Prepare the response + {} body %body + dup puts! +) +; The request handler is ready, give it the name handler +=handler + +; Create the parameter dictionary for the server +{} +handler %handler +5555 %port -;Start server +; Start server "Server started on port 5555." puts! "Press Ctrl+C to stop." puts! - -{} - handler %handler - 5555 %port start-server </code></pre></div></div>@@ -9401,7 +9411,7 @@
<p>Stops the currently-running HTTP server. This operator should be used within an HTTP server handler quotation.</p></div> </div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco – January 10, 2020</p> + <p><span class="copy"></span> Fabio Cevasco – January 13, 2020</p> <p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p> </div> </div>