akane.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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">validatePassword
  120. <li><a class="reference" href="#validatePassword%2Cstring%2Cstring"
  121. title="validatePassword(password, hashpassword: string): Future[bool]">validatePassword,<wbr>string,<wbr>string</a></li>
  122. </ul>
  123. <ul class="simple nested-toc-section">parseQuery
  124. <li><a class="reference" href="#parseQuery%2CRequest"
  125. title="parseQuery(request: Request): Future[JsonNode]">parseQuery,<wbr>Request</a></li>
  126. </ul>
  127. <ul class="simple nested-toc-section">loadtemplate
  128. <li><a class="reference" href="#loadtemplate%2Cstring%2CJsonNode"
  129. title="loadtemplate(name: string; json: JsonNode = %*{}): Future[string]">loadtemplate,<wbr>string,<wbr>JsonNode</a></li>
  130. </ul>
  131. <ul class="simple nested-toc-section">newCookie
  132. <li><a class="reference" href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"
  133. title="newCookie(server: ServerRef; key, value: string; domain = &quot;&quot;): HttpHeaders">newCookie,<wbr>ServerRef,<wbr>string,<wbr>string,<wbr>string</a></li>
  134. </ul>
  135. <ul class="simple nested-toc-section">password2hash
  136. <li><a class="reference" href="#password2hash%2Cstring"
  137. title="password2hash(password: string): Future[string]">password2hash,<wbr>string</a></li>
  138. </ul>
  139. </ul>
  140. </li>
  141. <li>
  142. <a class="reference reference-toplevel" href="#17" id="67">Macros</a>
  143. <ul class="simple simple-toc-section">
  144. <li><a class="reference" href="#pages.m%2CServerRef%2Cuntyped"
  145. title="pages(server: ServerRef; body: untyped): untyped">pages</a></li>
  146. <li><a class="reference" href="#send.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  147. title="send(request, message: untyped; http_code = Http200;
  148. headers: HttpHeaders = newHttpHeaders()): untyped">send</a></li>
  149. <li><a class="reference" href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  150. title="answer(request, message: untyped; http_code = Http200;
  151. headers: HttpHeaders = newHttpHeaders()): untyped">answer</a></li>
  152. <li><a class="reference" href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  153. title="error(request, message: untyped; http_code = Http404;
  154. headers: HttpHeaders = newHttpHeaders()): untyped">error</a></li>
  155. <li><a class="reference" href="#sendJson.m%2Cuntyped%2Cuntyped"
  156. title="sendJson(request, message: untyped; http_code = Http200): untyped">sendJson</a></li>
  157. <li><a class="reference" href="#sendPlaintext.m%2Cuntyped%2Cuntyped"
  158. title="sendPlaintext(request, message: untyped; http_code = Http200): untyped">sendPlaintext</a></li>
  159. <li><a class="reference" href="#start.m%2CServerRef"
  160. title="start(server: ServerRef): untyped">start</a></li>
  161. </ul>
  162. </li>
  163. </ul>
  164. </div>
  165. <div class="nine columns" id="content">
  166. <div id="tocRoot"></div>
  167. <p class="module-desc">
  168. <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>
  169. <span class="Identifier">my_sever</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span>
  170. <span class="StringLit">&quot;/&quot;</span><span class="Punctuation">:</span>
  171. <span class="Identifier">echo</span> <span class="StringLit">&quot;Index page&quot;</span>
  172. <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>
  173. <span class="Identifier">notfound</span><span class="Punctuation">:</span>
  174. <span class="Identifier">echo</span> <span class="StringLit">&quot;oops :(&quot;</span>
  175. <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>
  176. <div class="section" id="7">
  177. <h1><a class="toc-backref" href="#7">Types</a></h1>
  178. <dl class="item">
  179. <a id="ServerRef"></a>
  180. <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>
  181. <span class="Identifier">port</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">uint16</span>
  182. <span class="Identifier">address</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span>
  183. <span class="Identifier">server</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">AsyncHttpServer</span>
  184. </pre></dt>
  185. <dd>
  186. </dd>
  187. </dl></div>
  188. <div class="section" id="10">
  189. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  190. <dl class="item">
  191. <a id="AnyHttpMethod"></a>
  192. <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>
  193. <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>
  194. <dd>
  195. </dd>
  196. <a id="BaseHttpMethod"></a>
  197. <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>
  198. <dd>
  199. </dd>
  200. </dl></div>
  201. <div class="section" id="12">
  202. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  203. <dl class="item">
  204. <a id="newServer,string,uint16"></a>
  205. <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">
  206. <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>
  207. <dd>
  208. <p>Creates a new ServerRef object.</p>
  209. <p>Arguments:</p>
  210. <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>
  211. <li><tt class="docutils literal"><span class="pre">port</span></tt> - server port, e.g. 5000</li>
  212. </ul>
  213. <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>
  214. </dd>
  215. <a id="loadtemplate,string,JsonNode"></a>
  216. <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>
  217. <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>
  218. <dd>
  219. <p>Loads HTML template from <tt class="docutils literal"><span class="pre">templates</span></tt> folder.</p>
  220. <p>Arguments:</p>
  221. <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>
  222. <li><tt class="docutils literal"><span class="pre">json</span></tt> - Json data, which replaces in the template.</li>
  223. </ul>
  224. <p>Replaces:</p>
  225. <ul class="simple"><li>@key -&gt; value</li>
  226. <li>if @key { ... } -&gt; ... (if value is true)</li>
  227. <li>if not @key { ... } -&gt; ... (if value is false)</li>
  228. <li>for i in 0..@key { ... } -&gt; ........., etc</li>
  229. <li>@key[0] -&gt; key[0]</li>
  230. </ul>
  231. <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>
  232. </dd>
  233. <a id="parseQuery,Request"></a>
  234. <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">
  235. <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>
  236. <dd>
  237. Decodes query.<dl class="docutils"><dt>e.g.:</dt>
  238. <dd>&quot;a=5&amp;b=10&quot; -&gt; {&quot;a&quot;: &quot;5&quot;, &quot;b&quot;: &quot;10&quot;}</dd>
  239. </dl>
  240. <p>This also have debug output, if compiled in debug mode.</p>
  241. </dd>
  242. <a id="newCookie,ServerRef,string,string,string"></a>
  243. <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">
  244. <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>
  245. <dd>
  246. <p>Creates a new cookies</p>
  247. <p>Arguments:</p>
  248. <ul class="simple"><li><tt class="docutils literal"><span class="pre">key</span></tt> is a cookie key.</li>
  249. <li><tt class="docutils literal"><span class="pre">value</span></tt> is a new cookie value.</li>
  250. <li><tt class="docutils literal"><span class="pre">domain</span></tt> is a cookie doomain.</li>
  251. </ul>
  252. </dd>
  253. <a id="password2hash,string"></a>
  254. <dt><pre><span class="Keyword">proc</span> <a href="#password2hash%2Cstring"><span class="Identifier">password2hash</span></a><span class="Other">(</span><span class="Identifier">password</span><span class="Other">:</span> <span class="Identifier">string</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>
  255. <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>
  256. <dd>
  257. <p>Generates a sha1 from <tt class="docutils literal"><span class="pre">password</span></tt>.</p>
  258. <p>Arguments:</p>
  259. <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is an user password.</li>
  260. </ul>
  261. <p>WARNING! It's works only with <tt class="docutils literal"><span class="pre">-d:tools</span></tt>.</p>
  262. </dd>
  263. <a id="validatePassword,string,string"></a>
  264. <dt><pre><span class="Keyword">proc</span> <a href="#validatePassword%2Cstring%2Cstring"><span class="Identifier">validatePassword</span></a><span class="Other">(</span><span class="Identifier">password</span><span class="Other">,</span> <span class="Identifier">hashpassword</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">bool</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>
  265. <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>
  266. <dd>
  267. <p>Validates the password and returns true, if the password is valid.</p>
  268. <p>Arguments:</p>
  269. <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is a got password from user input.</li>
  270. <li><tt class="docutils literal"><span class="pre">hashpassword</span></tt> is a response from <a class="reference external" href="#password2hash,string">password2hash proc</a></li>
  271. </ul>
  272. <p>WARNING! It's works only with <tt class="docutils literal"><span class="pre">-d:tools</span></tt>.</p>
  273. </dd>
  274. </dl></div>
  275. <div class="section" id="17">
  276. <h1><a class="toc-backref" href="#17">Macros</a></h1>
  277. <dl class="item">
  278. <a id="pages.m,ServerRef,untyped"></a>
  279. <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>
  280. <dd>
  281. <p>This macro provides convenient page adding.</p>
  282. <p><tt class="docutils literal"><span class="pre">body</span></tt> should be StmtList. page type can be:</p>
  283. <ul class="simple"><li><tt class="docutils literal"><span class="pre">equals</span></tt></li>
  284. <li><tt class="docutils literal"><span class="pre">startswith</span></tt></li>
  285. <li><tt class="docutils literal"><span class="pre">endswith</span></tt></li>
  286. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - match url via regex.</li>
  287. <li><tt class="docutils literal"><span class="pre">notfound</span></tt> - this page uses without URL argument.</li>
  288. </ul>
  289. <p>When a new request to the server is received, variables are automatically created:</p>
  290. <ul class="simple"><li><tt class="docutils literal"><span class="pre">request</span></tt> - new Request.</li>
  291. <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>
  292. <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>
  293. <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>
  294. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - URL is matched text.</li>
  295. <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>
  296. </ul>
  297. </li>
  298. <li><tt class="docutils literal"><span class="pre">urlParams</span></tt> - query URL (in JSON).</li>
  299. <li><tt class="docutils literal"><span class="pre">decoded_url</span></tt> - URL always is request.url.path</li>
  300. <li><tt class="docutils literal"><span class="pre">cookies</span></tt> - StringTable of cookies.</li>
  301. </ul>
  302. <p><strong class="examples_text">Example:</strong></p>
  303. <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">
  304. </span><span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span><span class="Whitespace">
  305. </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">
  306. </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">url</span><span class="Whitespace">
  307. </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">urlParams</span><span class="Whitespace">
  308. </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">
  309. </span><span class="Comment"># You can also not write `equals(&quot;/&quot;)`:</span><span class="Whitespace">
  310. </span><span class="StringLit">&quot;/helloworld&quot;</span><span class="Punctuation">:</span><span class="Whitespace">
  311. </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>
  312. </dd>
  313. <a id="send.m,untyped,untyped,HttpHeaders"></a>
  314. <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>
  315. <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>
  316. <dd>
  317. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  318. <p>Translates to</p>
  319. <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>
  320. <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>
  321. </dd>
  322. <a id="answer.m,untyped,untyped,HttpHeaders"></a>
  323. <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>
  324. <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>
  325. <dd>
  326. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  327. <p>Translates to</p>
  328. <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>
  329. <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>
  330. </dd>
  331. <a id="error.m,untyped,untyped,HttpHeaders"></a>
  332. <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>
  333. <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>
  334. <dd>
  335. <p>Responds from server with utf-8. Note: Content-length not automatically sends.</p>
  336. <p>Translates to</p>
  337. <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>
  338. <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>
  339. </dd>
  340. <a id="sendJson.m,untyped,untyped"></a>
  341. <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>
  342. <dd>
  343. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  344. <p>Translates to</p>
  345. <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>
  346. <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>
  347. </dd>
  348. <a id="sendPlaintext.m,untyped,untyped"></a>
  349. <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>
  350. <dd>
  351. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  352. <p>Translates to</p>
  353. <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>
  354. <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>
  355. </dd>
  356. <a id="start.m,ServerRef"></a>
  357. <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>
  358. <dd>
  359. Starts server.
  360. <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>
  361. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">start</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  362. </dd>
  363. </dl></div>
  364. </div>
  365. </div>
  366. <div class="row">
  367. <div class="twelve-columns footer">
  368. <span class="nim-sprite"></span>
  369. <br/>
  370. <small style="color: var(--hint);">Made with Nim. Generated: 2023-03-29 07:13:26 UTC</small>
  371. </div>
  372. </div>
  373. </div>
  374. </div>
  375. </body>
  376. </html>