akane.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <!-- This file is generated by Nim. -->
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <!-- Favicon -->
  10. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  11. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  12. <!-- Google fonts -->
  13. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  14. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  15. <!-- CSS -->
  16. <title>akane</title>
  17. <link rel="stylesheet" type="text/css" href="nimdoc.out.css">
  18. <script type="text/javascript" src="dochack.js"></script>
  19. <script type="text/javascript">
  20. function main() {
  21. var pragmaDots = document.getElementsByClassName("pragmadots");
  22. for (var i = 0; i < pragmaDots.length; i++) {
  23. pragmaDots[i].onclick = function(event) {
  24. // Hide tease
  25. event.target.parentNode.style.display = "none";
  26. // Show actual
  27. event.target.parentNode.nextElementSibling.style.display = "inline";
  28. }
  29. }
  30. const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
  31. function switchTheme(e) {
  32. if (e.target.checked) {
  33. document.documentElement.setAttribute('data-theme', 'dark');
  34. localStorage.setItem('theme', 'dark');
  35. } else {
  36. document.documentElement.setAttribute('data-theme', 'light');
  37. localStorage.setItem('theme', 'light');
  38. }
  39. }
  40. toggleSwitch.addEventListener('change', switchTheme, false);
  41. const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
  42. if (currentTheme) {
  43. document.documentElement.setAttribute('data-theme', currentTheme);
  44. if (currentTheme === 'dark') {
  45. toggleSwitch.checked = true;
  46. }
  47. }
  48. }
  49. </script>
  50. </head>
  51. <body onload="main()">
  52. <div class="document" id="documentId">
  53. <div class="container">
  54. <h1 class="title">akane</h1>
  55. <div class="row">
  56. <div class="three columns">
  57. <div class="theme-switch-wrapper">
  58. <label class="theme-switch" for="checkbox">
  59. <input type="checkbox" id="checkbox" />
  60. <div class="slider round"></div>
  61. </label>
  62. &nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
  63. </div>
  64. <div id="global-links">
  65. <ul class="simple">
  66. <li>
  67. <a href="theindex.html">Index</a>
  68. </li>
  69. </ul>
  70. </div>
  71. <div id="searchInputDiv">
  72. Search: <input type="text" id="searchInput"
  73. onkeyup="search()" />
  74. </div>
  75. <div>
  76. Group by:
  77. <select onchange="groupBy(this.value)">
  78. <option value="section">Section</option>
  79. <option value="type">Type</option>
  80. </select>
  81. </div>
  82. <ul class="simple simple-toc" id="toc-list">
  83. <ul class="simple"><li><a class="reference" id="simple-usage_toc" href="#simple-usage">Simple usage</a></li>
  84. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  85. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  86. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  87. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  88. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  89. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  90. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  91. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  92. </ul><li>
  93. <a class="reference reference-toplevel" href="#7" id="57">Types</a>
  94. <ul class="simple simple-toc-section">
  95. <li><a class="reference" href="#ServerRef"
  96. title="ServerRef = ref object
  97. port*: uint16
  98. address*: string
  99. server*: AsyncHttpServer">ServerRef</a></li>
  100. </ul>
  101. </li>
  102. <li>
  103. <a class="reference reference-toplevel" href="#10" id="60">Consts</a>
  104. <ul class="simple simple-toc-section">
  105. <li><a class="reference" href="#AnyHttpMethod"
  106. title="AnyHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete, HttpTrace,
  107. HttpOptions, HttpConnect, HttpPatch]">AnyHttpMethod</a></li>
  108. <li><a class="reference" href="#BaseHttpMethod"
  109. title="BaseHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete]">BaseHttpMethod</a></li>
  110. </ul>
  111. </li>
  112. <li>
  113. <a class="reference reference-toplevel" href="#12" id="62">Procs</a>
  114. <ul class="simple simple-toc-section">
  115. <ul class="simple nested-toc-section">newServer
  116. <li><a class="reference" href="#newServer%2Cstring%2Cuint16"
  117. title="newServer(address: string = &quot;127.0.0.1&quot;; port: uint16 = 5000): ServerRef">newServer,<wbr>string,<wbr>uint16</a></li>
  118. </ul>
  119. <ul class="simple nested-toc-section">parseQuery
  120. <li><a class="reference" href="#parseQuery%2CRequest"
  121. title="parseQuery(request: Request): Future[JsonNode]">parseQuery,<wbr>Request</a></li>
  122. </ul>
  123. <ul class="simple nested-toc-section">loadtemplate
  124. <li><a class="reference" href="#loadtemplate%2Cstring%2CJsonNode"
  125. title="loadtemplate(name: string; json: JsonNode = %*{}): Future[string]">loadtemplate,<wbr>string,<wbr>JsonNode</a></li>
  126. </ul>
  127. <ul class="simple nested-toc-section">newCookie
  128. <li><a class="reference" href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"
  129. title="newCookie(server: ServerRef; key, value: string; domain = &quot;&quot;): HttpHeaders">newCookie,<wbr>ServerRef,<wbr>string,<wbr>string,<wbr>string</a></li>
  130. </ul>
  131. </ul>
  132. </li>
  133. <li>
  134. <a class="reference reference-toplevel" href="#17" id="67">Macros</a>
  135. <ul class="simple simple-toc-section">
  136. <li><a class="reference" href="#pages.m%2CServerRef%2Cuntyped"
  137. title="pages(server: ServerRef; body: untyped): untyped">pages</a></li>
  138. <li><a class="reference" href="#send.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  139. title="send(request, message: untyped; http_code = Http200;
  140. headers: HttpHeaders = newHttpHeaders()): untyped">send</a></li>
  141. <li><a class="reference" href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  142. title="answer(request, message: untyped; http_code = Http200;
  143. headers: HttpHeaders = newHttpHeaders()): untyped">answer</a></li>
  144. <li><a class="reference" href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  145. title="error(request, message: untyped; http_code = Http404;
  146. headers: HttpHeaders = newHttpHeaders()): untyped">error</a></li>
  147. <li><a class="reference" href="#sendJson.m%2Cuntyped%2Cuntyped"
  148. title="sendJson(request, message: untyped; http_code = Http200): untyped">sendJson</a></li>
  149. <li><a class="reference" href="#sendPlaintext.m%2Cuntyped%2Cuntyped"
  150. title="sendPlaintext(request, message: untyped; http_code = Http200): untyped">sendPlaintext</a></li>
  151. <li><a class="reference" href="#start.m%2CServerRef"
  152. title="start(server: ServerRef): untyped">start</a></li>
  153. </ul>
  154. </li>
  155. </ul>
  156. </div>
  157. <div class="nine columns" id="content">
  158. <div id="tocRoot"></div>
  159. <p class="module-desc">
  160. <h2><a class="toc-backref" id="simple-usage" href="#simple-usage">Simple usage</a></h2><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">my_server</span> <span class="Operator">=</span> <span class="Identifier">newServer</span><span class="Punctuation">(</span><span class="StringLit">&quot;127.0.0.1&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">8080</span><span class="Punctuation">)</span> <span class="Comment"># starts server at https://127.0.0.1:8080</span>
  161. <span class="Identifier">my_sever</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span>
  162. <span class="StringLit">&quot;/&quot;</span><span class="Punctuation">:</span>
  163. <span class="Identifier">echo</span> <span class="StringLit">&quot;Index page&quot;</span>
  164. <span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">answer</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello, world!&quot;</span><span class="Punctuation">)</span>
  165. <span class="Identifier">notfound</span><span class="Punctuation">:</span>
  166. <span class="Identifier">echo</span> <span class="StringLit">&quot;oops :(&quot;</span>
  167. <span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">error</span><span class="Punctuation">(</span><span class="StringLit">&quot;404 Page not found.&quot;</span><span class="Punctuation">)</span></pre></p>
  168. <div class="section" id="7">
  169. <h1><a class="toc-backref" href="#7">Types</a></h1>
  170. <dl class="item">
  171. <a id="ServerRef"></a>
  172. <dt><pre><a href="akane.html#ServerRef"><span class="Identifier">ServerRef</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  173. <span class="Identifier">port</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">uint16</span>
  174. <span class="Identifier">address</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span>
  175. <span class="Identifier">server</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">AsyncHttpServer</span>
  176. </pre></dt>
  177. <dd>
  178. </dd>
  179. </dl></div>
  180. <div class="section" id="10">
  181. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  182. <dl class="item">
  183. <a id="AnyHttpMethod"></a>
  184. <dt><pre><a href="akane.html#AnyHttpMethod"><span class="Identifier">AnyHttpMethod</span></a> <span class="Other">=</span> <span class="Other">[</span><span class="DecNumber">HttpHead</span><span class="Other">,</span> <span class="DecNumber">HttpGet</span><span class="Other">,</span> <span class="DecNumber">HttpPost</span><span class="Other">,</span> <span class="DecNumber">HttpPut</span><span class="Other">,</span> <span class="DecNumber">HttpDelete</span><span class="Other">,</span> <span class="DecNumber">HttpTrace</span><span class="Other">,</span>
  185. <span class="DecNumber">HttpOptions</span><span class="Other">,</span> <span class="DecNumber">HttpConnect</span><span class="Other">,</span> <span class="DecNumber">HttpPatch</span><span class="Other">]</span></pre></dt>
  186. <dd>
  187. </dd>
  188. <a id="BaseHttpMethod"></a>
  189. <dt><pre><a href="akane.html#BaseHttpMethod"><span class="Identifier">BaseHttpMethod</span></a> <span class="Other">=</span> <span class="Other">[</span><span class="DecNumber">HttpHead</span><span class="Other">,</span> <span class="DecNumber">HttpGet</span><span class="Other">,</span> <span class="DecNumber">HttpPost</span><span class="Other">,</span> <span class="DecNumber">HttpPut</span><span class="Other">,</span> <span class="DecNumber">HttpDelete</span><span class="Other">]</span></pre></dt>
  190. <dd>
  191. </dd>
  192. </dl></div>
  193. <div class="section" id="12">
  194. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  195. <dl class="item">
  196. <a id="newServer,string,uint16"></a>
  197. <dt><pre><span class="Keyword">proc</span> <a href="#newServer%2Cstring%2Cuint16"><span class="Identifier">newServer</span></a><span class="Other">(</span><span class="Identifier">address</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Other">=</span> <span class="StringLit">&quot;127.0.0.1&quot;</span><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <span class="Identifier">uint16</span> <span class="Other">=</span> <span class="DecNumber">5000</span><span class="Other">)</span><span class="Other">:</span> <a href="akane.html#ServerRef"><span class="Identifier">ServerRef</span></a> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma">
  198. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">WriteDirEffect</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
  199. <dd>
  200. <p>Creates a new ServerRef object.</p>
  201. <p>Arguments:</p>
  202. <ul class="simple"><li><tt class="docutils literal"><span class="pre">address</span></tt> - server address, e.g. &quot;127.0.0.1&quot;</li>
  203. <li><tt class="docutils literal"><span class="pre">port</span></tt> - server port, e.g. 5000</li>
  204. </ul>
  205. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">server</span> <span class="Operator">=</span> <span class="Identifier">newServer</span><span class="Punctuation">(</span><span class="StringLit">&quot;127.0.0.1&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">5000</span><span class="Punctuation">)</span></pre>
  206. </dd>
  207. <a id="loadtemplate,string,JsonNode"></a>
  208. <dt><pre><span class="Keyword">proc</span> <a href="#loadtemplate%2Cstring%2CJsonNode"><span class="Identifier">loadtemplate</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">json</span><span class="Other">:</span> <span class="Identifier">JsonNode</span> <span class="Other">=</span> <span class="Operator">%*</span><span class="Other">{</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">inline</span><span class="Other">,</span>
  209. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
  210. <dd>
  211. <p>Loads HTML template from <tt class="docutils literal"><span class="pre">templates</span></tt> folder.</p>
  212. <p>Arguments:</p>
  213. <ul class="simple"><li><tt class="docutils literal"><span class="pre">name</span></tt> - template's name, e.g. &quot;index&quot;, &quot;api&quot;, etc.</li>
  214. <li><tt class="docutils literal"><span class="pre">json</span></tt> - Json data, which replaces in the template.</li>
  215. </ul>
  216. <p>Replaces:</p>
  217. <ul class="simple"><li>@key -&gt; value</li>
  218. <li>if @key { ... } -&gt; ... (if value is true)</li>
  219. <li>if not @key { ... } -&gt; ... (if value is false)</li>
  220. <li>for i in 0..@key { ... } -&gt; ........., etc</li>
  221. <li>@key[0] -&gt; key[0]</li>
  222. </ul>
  223. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Keyword">let</span> <span class="Keyword">template</span> <span class="Operator">=</span> <span class="Identifier">loadtemplate</span><span class="Punctuation">(</span><span class="StringLit">&quot;index.html&quot;</span><span class="Punctuation">,</span> <span class="Operator">%*</span><span class="Punctuation">{</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">:</span> <span class="DecNumber">5</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
  224. </dd>
  225. <a id="parseQuery,Request"></a>
  226. <dt><pre><span class="Keyword">proc</span> <a href="#parseQuery%2CRequest"><span class="Identifier">parseQuery</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">:</span> <span class="Identifier">Request</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">JsonNode</span><span class="Other">]</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma">
  227. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
  228. <dd>
  229. Decodes query.<dl class="docutils"><dt>e.g.:</dt>
  230. <dd>&quot;a=5&amp;b=10&quot; -&gt; {&quot;a&quot;: &quot;5&quot;, &quot;b&quot;: &quot;10&quot;}</dd>
  231. </dl>
  232. <p>This also have debug output, if compiled in debug mode.</p>
  233. </dd>
  234. <a id="newCookie,ServerRef,string,string,string"></a>
  235. <dt><pre><span class="Keyword">proc</span> <a href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"><span class="Identifier">newCookie</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="akane.html#ServerRef"><span class="Identifier">ServerRef</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">;</span> <span class="Identifier">domain</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">HttpHeaders</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma">
  236. <span class="Identifier">inline</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
  237. <dd>
  238. <p>Creates a new cookies</p>
  239. <p>Arguments:</p>
  240. <ul class="simple"><li><tt class="docutils literal"><span class="pre">key</span></tt> is a cookie key.</li>
  241. <li><tt class="docutils literal"><span class="pre">value</span></tt> is a new cookie value.</li>
  242. <li><tt class="docutils literal"><span class="pre">domain</span></tt> is a cookie doomain.</li>
  243. </ul>
  244. </dd>
  245. </dl></div>
  246. <div class="section" id="17">
  247. <h1><a class="toc-backref" href="#17">Macros</a></h1>
  248. <dl class="item">
  249. <a id="pages.m,ServerRef,untyped"></a>
  250. <dt><pre><span class="Keyword">macro</span> <a href="#pages.m%2CServerRef%2Cuntyped"><span class="Identifier">pages</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="akane.html#ServerRef"><span class="Identifier">ServerRef</span></a><span class="Other">;</span> <span class="Identifier">body</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  251. <dd>
  252. <p>This macro provides convenient page adding.</p>
  253. <p><tt class="docutils literal"><span class="pre">body</span></tt> should be StmtList. page type can be:</p>
  254. <ul class="simple"><li><tt class="docutils literal"><span class="pre">equals</span></tt></li>
  255. <li><tt class="docutils literal"><span class="pre">startswith</span></tt></li>
  256. <li><tt class="docutils literal"><span class="pre">endswith</span></tt></li>
  257. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - match url via regex.</li>
  258. <li><tt class="docutils literal"><span class="pre">notfound</span></tt> - this page uses without URL argument.</li>
  259. </ul>
  260. <p>When a new request to the server is received, variables are automatically created:</p>
  261. <ul class="simple"><li><tt class="docutils literal"><span class="pre">request</span></tt> - new Request.</li>
  262. <li><tt class="docutils literal"><span class="pre">url</span></tt> - matched URL.<ul class="simple"><li><tt class="docutils literal"><span class="pre">equals</span></tt> - URL is request.url.path</li>
  263. <li><tt class="docutils literal"><span class="pre">startswith</span></tt> - URL is text after <tt class="docutils literal"><span class="pre">startswith</span></tt>.</li>
  264. <li><tt class="docutils literal"><span class="pre">endswith</span></tt> - URL is text before <tt class="docutils literal"><span class="pre">endswith</span></tt>.</li>
  265. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - URL is matched text.</li>
  266. <li><tt class="docutils literal"><span class="pre">notfound</span></tt> - <tt class="docutils literal"><span class="pre">url</span></tt> param not created.</li>
  267. </ul>
  268. </li>
  269. <li><tt class="docutils literal"><span class="pre">urlParams</span></tt> - query URL (in JSON).</li>
  270. <li><tt class="docutils literal"><span class="pre">decoded_url</span></tt> - URL always is request.url.path</li>
  271. <li><tt class="docutils literal"><span class="pre">cookies</span></tt> - StringTable of cookies.</li>
  272. </ul>
  273. <p><strong class="examples_text">Example:</strong></p>
  274. <pre class="listing"><span class="Keyword">let</span><span class="Whitespace"> </span><span class="Identifier">server</span><span class="Whitespace"> </span><span class="Operator">=</span><span class="Whitespace"> </span><span class="Identifier">newServer</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Whitespace">
  275. </span><span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span><span class="Whitespace">
  276. </span><span class="Identifier">equals</span><span class="Punctuation">(</span><span class="StringLit">&quot;/home&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span><span class="Whitespace">
  277. </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">url</span><span class="Whitespace">
  278. </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">urlParams</span><span class="Whitespace">
  279. </span><span class="Identifier">await</span><span class="Whitespace"> </span><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">answer</span><span class="Punctuation">(</span><span class="StringLit">&quot;Home&quot;</span><span class="Punctuation">)</span><span class="Whitespace">
  280. </span><span class="Comment"># You can also not write `equals(&quot;/&quot;)`:</span><span class="Whitespace">
  281. </span><span class="StringLit">&quot;/helloworld&quot;</span><span class="Punctuation">:</span><span class="Whitespace">
  282. </span><span class="Identifier">await</span><span class="Whitespace"> </span><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">answer</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello, world&quot;</span><span class="Punctuation">)</span></pre>
  283. </dd>
  284. <a id="send.m,untyped,untyped,HttpHeaders"></a>
  285. <dt><pre><span class="Keyword">macro</span> <a href="#send.m%2Cuntyped%2Cuntyped%2CHttpHeaders"><span class="Identifier">send</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">,</span> <span class="Identifier">message</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">;</span> <span class="Identifier">http_code</span> <span class="Other">=</span> <span class="Identifier">Http200</span><span class="Other">;</span>
  286. <span class="Identifier">headers</span><span class="Other">:</span> <span class="Identifier">HttpHeaders</span> <span class="Other">=</span> <span class="Identifier">newHttpHeaders</span><span class="Other">(</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  287. <dd>
  288. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  289. <p>Translates to</p>
  290. <pre class="listing"><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="Operator">$</span><span class="Identifier">message</span><span class="Punctuation">,</span> <span class="Identifier">headers</span><span class="Punctuation">)</span></pre>
  291. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">send</span><span class="Punctuation">(</span><span class="StringLit">&quot;hello!&quot;</span><span class="Punctuation">)</span></pre>
  292. </dd>
  293. <a id="answer.m,untyped,untyped,HttpHeaders"></a>
  294. <dt><pre><span class="Keyword">macro</span> <a href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"><span class="Identifier">answer</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">,</span> <span class="Identifier">message</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">;</span> <span class="Identifier">http_code</span> <span class="Other">=</span> <span class="Identifier">Http200</span><span class="Other">;</span>
  295. <span class="Identifier">headers</span><span class="Other">:</span> <span class="Identifier">HttpHeaders</span> <span class="Other">=</span> <span class="Identifier">newHttpHeaders</span><span class="Other">(</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  296. <dd>
  297. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  298. <p>Translates to</p>
  299. <pre class="listing"><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&lt;head&gt;&lt;meta charset='utf-8'&gt;&lt;/head&gt;&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">message</span><span class="Punctuation">,</span> <span class="Identifier">headers</span><span class="Punctuation">)</span></pre>
  300. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">answer</span><span class="Punctuation">(</span><span class="StringLit">&quot;hello!&quot;</span><span class="Punctuation">)</span></pre>
  301. </dd>
  302. <a id="error.m,untyped,untyped,HttpHeaders"></a>
  303. <dt><pre><span class="Keyword">macro</span> <a href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"><span class="Identifier">error</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">,</span> <span class="Identifier">message</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">;</span> <span class="Identifier">http_code</span> <span class="Other">=</span> <span class="Identifier">Http404</span><span class="Other">;</span>
  304. <span class="Identifier">headers</span><span class="Other">:</span> <span class="Identifier">HttpHeaders</span> <span class="Other">=</span> <span class="Identifier">newHttpHeaders</span><span class="Other">(</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  305. <dd>
  306. <p>Responds from server with utf-8. Note: Content-length not automatically sends.</p>
  307. <p>Translates to</p>
  308. <pre class="listing"><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http404</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&lt;head&gt;&lt;meta charset='utf-8'&gt;&lt;/head&gt;&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">message</span><span class="Punctuation">)</span></pre>
  309. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">error</span><span class="Punctuation">(</span><span class="StringLit">&quot;Oops! :(&quot;</span><span class="Punctuation">)</span></pre>
  310. </dd>
  311. <a id="sendJson.m,untyped,untyped"></a>
  312. <dt><pre><span class="Keyword">macro</span> <a href="#sendJson.m%2Cuntyped%2Cuntyped"><span class="Identifier">sendJson</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">,</span> <span class="Identifier">message</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">;</span> <span class="Identifier">http_code</span> <span class="Other">=</span> <span class="Identifier">Http200</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  313. <dd>
  314. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  315. <p>Translates to</p>
  316. <pre class="listing"><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="Operator">$</span><span class="Identifier">message</span><span class="Punctuation">,</span> <span class="Identifier">newHttpHeaders</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">&quot;Content-Type&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;application/json&quot;</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  317. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">sendJson</span><span class="Punctuation">(</span><span class="Operator">%*</span><span class="Punctuation">{</span><span class="StringLit">&quot;response&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;error&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;msg&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;oops :(&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
  318. </dd>
  319. <a id="sendPlaintext.m,untyped,untyped"></a>
  320. <dt><pre><span class="Keyword">macro</span> <a href="#sendPlaintext.m%2Cuntyped%2Cuntyped"><span class="Identifier">sendPlaintext</span></a><span class="Other">(</span><span class="Identifier">request</span><span class="Other">,</span> <span class="Identifier">message</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">;</span> <span class="Identifier">http_code</span> <span class="Other">=</span> <span class="Identifier">Http200</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  321. <dd>
  322. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  323. <p>Translates to</p>
  324. <pre class="listing"><span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="Operator">$</span><span class="Identifier">message</span><span class="Punctuation">,</span> <span class="Identifier">newHttpHeaders</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">&quot;Content-Type&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;plain/text&quot;</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  325. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Identifier">await</span> <span class="Identifier">request</span><span class="Operator">.</span><span class="Identifier">sendPlaintext</span><span class="Punctuation">(</span><span class="Operator">%*</span><span class="Punctuation">{</span><span class="StringLit">&quot;response&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;error&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;msg&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;oops :(&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
  326. </dd>
  327. <a id="start.m,ServerRef"></a>
  328. <dt><pre><span class="Keyword">macro</span> <a href="#start.m%2CServerRef"><span class="Identifier">start</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="akane.html#ServerRef"><span class="Identifier">ServerRef</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
  329. <dd>
  330. Starts server.
  331. <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><pre class="listing"><span class="Keyword">let</span> <span class="Identifier">server</span> <span class="Operator">=</span> <span class="Identifier">newServer</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  332. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">start</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  333. </dd>
  334. </dl></div>
  335. </div>
  336. </div>
  337. <div class="row">
  338. <div class="twelve-columns footer">
  339. <span class="nim-sprite"></span>
  340. <br/>
  341. <small style="color: var(--hint);">Made with Nim. Generated: 2021-07-05 10:52:38 UTC</small>
  342. </div>
  343. </div>
  344. </div>
  345. </div>
  346. </body>
  347. </html>