akane.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  42. document.documentElement.setAttribute('data-theme', "dark");
  43. toggleSwitch.checked = true;
  44. } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
  45. document.documentElement.setAttribute('data-theme', "light");
  46. toggleSwitch.checked = false;
  47. } else {
  48. const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
  49. if (currentTheme) {
  50. document.documentElement.setAttribute('data-theme', currentTheme);
  51. if (currentTheme === 'dark') {
  52. toggleSwitch.checked = true;
  53. }
  54. }
  55. }
  56. }
  57. </script>
  58. </head>
  59. <body onload="main()">
  60. <div class="document" id="documentId">
  61. <div class="container">
  62. <h1 class="title">akane</h1>
  63. <div class="row">
  64. <div class="three columns">
  65. <div class="theme-switch-wrapper">
  66. <label class="theme-switch" for="checkbox">
  67. <input type="checkbox" id="checkbox" />
  68. <div class="slider round"></div>
  69. </label>
  70. &nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
  71. </div>
  72. <div id="global-links">
  73. <ul class="simple">
  74. </ul>
  75. </div>
  76. <div id="searchInputDiv">
  77. Search: <input type="text" id="searchInput"
  78. onkeyup="search()" />
  79. </div>
  80. <div>
  81. Group by:
  82. <select onchange="groupBy(this.value)">
  83. <option value="section">Section</option>
  84. <option value="type">Type</option>
  85. </select>
  86. </div>
  87. <ul class="simple simple-toc" id="toc-list">
  88. <ul class="simple"><li><a class="reference" id="simple-usage_toc" href="#simple-usage">Simple usage</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. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  93. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  94. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  95. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  96. <li><a class="reference" id="example_toc" href="#example">Example</a></li>
  97. </ul><li>
  98. <a class="reference reference-toplevel" href="#7" id="57">Types</a>
  99. <ul class="simple simple-toc-section">
  100. <li><a class="reference" href="#ServerRef"
  101. title="ServerRef = ref object
  102. port*: uint16
  103. address*: string
  104. server*: AsyncHttpServer"><wbr />Server<wbr />Ref<span class="attachedType"></span></a></li>
  105. </ul>
  106. </li>
  107. <li>
  108. <a class="reference reference-toplevel" href="#10" id="60">Consts</a>
  109. <ul class="simple simple-toc-section">
  110. <li><a class="reference" href="#AnyHttpMethod"
  111. title="AnyHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete, HttpTrace,
  112. HttpOptions, HttpConnect, HttpPatch]"><wbr />Any<wbr />Http<wbr />Method<span class="attachedType"></span></a></li>
  113. <li><a class="reference" href="#BaseHttpMethod"
  114. title="BaseHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete]"><wbr />Base<wbr />Http<wbr />Method<span class="attachedType"></span></a></li>
  115. </ul>
  116. </li>
  117. <li>
  118. <a class="reference reference-toplevel" href="#12" id="62">Procs</a>
  119. <ul class="simple simple-toc-section">
  120. <li><a class="reference" href="#newServer%2Cstring%2Cuint16"
  121. title="newServer(address: string = &quot;127.0.0.1&quot;; port: uint16 = 5000): ServerRef"><wbr />new<wbr />Server<span class="attachedType">ServerRef</span></a></li>
  122. <li><a class="reference" href="#loadtemplate%2Cstring%2CJsonNode"
  123. title="loadtemplate(name: string; json: JsonNode = %*{}): Future[string]"><wbr />loadtemplate<span class="attachedType"></span></a></li>
  124. <li><a class="reference" href="#parseQuery%2CRequest"
  125. title="parseQuery(request: Request): Future[JsonNode]"><wbr />parse<wbr />Query<span class="attachedType"></span></a></li>
  126. <li><a class="reference" href="#password2hash%2Cstring"
  127. title="password2hash(password: string): Future[string]"><wbr />password2hash<span class="attachedType"></span></a></li>
  128. <li><a class="reference" href="#validatePassword%2Cstring%2Cstring"
  129. title="validatePassword(password, hashpassword: string): Future[bool]"><wbr />validate<wbr />Password<span class="attachedType"></span></a></li>
  130. <li><a class="reference" href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"
  131. title="newCookie(server: ServerRef; key, value: string; domain = &quot;&quot;): HttpHeaders"><wbr />new<wbr />Cookie<span class="attachedType">ServerRef</span></a></li>
  132. </ul>
  133. </li>
  134. <li>
  135. <a class="reference reference-toplevel" href="#17" id="67">Macros</a>
  136. <ul class="simple simple-toc-section">
  137. <li><a class="reference" href="#pages.m%2CServerRef%2Cuntyped"
  138. title="pages(server: ServerRef; body: untyped): untyped"><wbr />pages<span class="attachedType">ServerRef</span></a></li>
  139. <li><a class="reference" href="#send.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  140. title="send(request, message: untyped; http_code = Http200;
  141. headers: HttpHeaders = newHttpHeaders()): untyped"><wbr />send<span class="attachedType"></span></a></li>
  142. <li><a class="reference" href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  143. title="answer(request, message: untyped; http_code = Http200;
  144. headers: HttpHeaders = newHttpHeaders()): untyped"><wbr />answer<span class="attachedType"></span></a></li>
  145. <li><a class="reference" href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
  146. title="error(request, message: untyped; http_code = Http404;
  147. headers: HttpHeaders = newHttpHeaders()): untyped"><wbr />error<span class="attachedType"></span></a></li>
  148. <li><a class="reference" href="#sendJson.m%2Cuntyped%2Cuntyped"
  149. title="sendJson(request, message: untyped; http_code = Http200): untyped"><wbr />send<wbr />Json<span class="attachedType"></span></a></li>
  150. <li><a class="reference" href="#sendPlaintext.m%2Cuntyped%2Cuntyped"
  151. title="sendPlaintext(request, message: untyped; http_code = Http200): untyped"><wbr />send<wbr />Plaintext<span class="attachedType"></span></a></li>
  152. <li><a class="reference" href="#start.m%2CServerRef"
  153. title="start(server: ServerRef): untyped"><wbr />start<span class="attachedType">ServerRef</span></a></li>
  154. </ul>
  155. </li>
  156. </ul>
  157. </div>
  158. <div class="nine columns" id="content">
  159. <div id="tocRoot"></div>
  160. <p class="module-desc">
  161. <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>
  162. <span class="Identifier">my_sever</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span>
  163. <span class="StringLit">&quot;/&quot;</span><span class="Punctuation">:</span>
  164. <span class="Identifier">echo</span> <span class="StringLit">&quot;Index page&quot;</span>
  165. <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>
  166. <span class="Identifier">notfound</span><span class="Punctuation">:</span>
  167. <span class="Identifier">echo</span> <span class="StringLit">&quot;oops :(&quot;</span>
  168. <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>
  169. <div class="section" id="7">
  170. <h1><a class="toc-backref" href="#7">Types</a></h1>
  171. <dl class="item">
  172. <a id="ServerRef"></a>
  173. <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>
  174. <span class="Identifier">port</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">uint16</span>
  175. <span class="Identifier">address</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span>
  176. <span class="Identifier">server</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">AsyncHttpServer</span>
  177. </pre></dt>
  178. <dd>
  179. </dd>
  180. </dl></div>
  181. <div class="section" id="10">
  182. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  183. <dl class="item">
  184. <a id="AnyHttpMethod"></a>
  185. <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>
  186. <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>
  187. <dd>
  188. </dd>
  189. <a id="BaseHttpMethod"></a>
  190. <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>
  191. <dd>
  192. </dd>
  193. </dl></div>
  194. <div class="section" id="12">
  195. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  196. <dl class="item">
  197. <a id="newServer,string,uint16"></a>
  198. <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">
  199. <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>
  200. <dd>
  201. <p>Creates a new ServerRef object.</p>
  202. <p>Arguments:</p>
  203. <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>
  204. <li><tt class="docutils literal"><span class="pre">port</span></tt> - server port, e.g. 5000</li>
  205. </ul>
  206. <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>
  207. </dd>
  208. <a id="loadtemplate,string,JsonNode"></a>
  209. <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>
  210. <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="Identifier">FutureError</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>
  211. <dd>
  212. <p>Loads HTML template from <tt class="docutils literal"><span class="pre">templates</span></tt> folder.</p>
  213. <p>Arguments:</p>
  214. <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>
  215. <li><tt class="docutils literal"><span class="pre">json</span></tt> - Json data, which replaces in the template.</li>
  216. </ul>
  217. <p>Replaces:</p>
  218. <ul class="simple"><li>@key -&gt; value</li>
  219. <li>if @key { ... } -&gt; ... (if value is true)</li>
  220. <li>if not @key { ... } -&gt; ... (if value is false)</li>
  221. <li>for i in 0..@key { ... } -&gt; ........., etc</li>
  222. <li>@key[0] -&gt; key[0]</li>
  223. </ul>
  224. <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>
  225. </dd>
  226. <a id="parseQuery,Request"></a>
  227. <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">
  228. <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="Identifier">FutureError</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>
  229. <dd>
  230. Decodes query.<dl class="docutils"><dt>e.g.:</dt>
  231. <dd>&quot;a=5&amp;b=10&quot; -&gt; {&quot;a&quot;: &quot;5&quot;, &quot;b&quot;: &quot;10&quot;}</dd>
  232. </dl>
  233. <p>This also have debug output, if compiled in debug mode.</p>
  234. </dd>
  235. <a id="password2hash,string"></a>
  236. <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>
  237. <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="Identifier">FutureError</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>
  238. <dd>
  239. <p>Generates a sha1 from <tt class="docutils literal"><span class="pre">password</span></tt>.</p>
  240. <p>Arguments:</p>
  241. <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is an user password.</li>
  242. </ul>
  243. </dd>
  244. <a id="validatePassword,string,string"></a>
  245. <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>
  246. <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="Identifier">FutureError</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>
  247. <dd>
  248. <p>Validates the password and returns true, if the password is valid.</p>
  249. <p>Arguments:</p>
  250. <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is a got password from user input.</li>
  251. <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>
  252. </ul>
  253. </dd>
  254. <a id="newCookie,ServerRef,string,string,string"></a>
  255. <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"><span class="Identifier">inline</span><span class="Other">,</span>
  256. <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>
  257. <dd>
  258. <p>Creates a new cookies</p>
  259. <p>Arguments:</p>
  260. <ul class="simple"><li><tt class="docutils literal"><span class="pre">key</span></tt> is a cookie key.</li>
  261. <li><tt class="docutils literal"><span class="pre">value</span></tt> is a new cookie value.</li>
  262. <li><tt class="docutils literal"><span class="pre">domain</span></tt> is a cookie doomain.</li>
  263. </ul>
  264. </dd>
  265. </dl></div>
  266. <div class="section" id="17">
  267. <h1><a class="toc-backref" href="#17">Macros</a></h1>
  268. <dl class="item">
  269. <a id="pages.m,ServerRef,untyped"></a>
  270. <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>
  271. <dd>
  272. <p>This macro provides convenient page adding.</p>
  273. <p><tt class="docutils literal"><span class="pre">body</span></tt> should be StmtList. page type can be:</p>
  274. <ul class="simple"><li><tt class="docutils literal"><span class="pre">equals</span></tt></li>
  275. <li><tt class="docutils literal"><span class="pre">startswith</span></tt></li>
  276. <li><tt class="docutils literal"><span class="pre">endswith</span></tt></li>
  277. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - match url via regex.</li>
  278. <li><tt class="docutils literal"><span class="pre">notfound</span></tt> - this page uses without URL argument.</li>
  279. </ul>
  280. <p>When a new request to the server is received, variables are automatically created:</p>
  281. <ul class="simple"><li><tt class="docutils literal"><span class="pre">request</span></tt> - new Request.</li>
  282. <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>
  283. <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>
  284. <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>
  285. <li><tt class="docutils literal"><span class="pre">regex</span></tt> - URL is matched text.</li>
  286. <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>
  287. </ul>
  288. </li>
  289. <li><tt class="docutils literal"><span class="pre">urlParams</span></tt> - query URL (in JSON).</li>
  290. <li><tt class="docutils literal"><span class="pre">decoded_url</span></tt> - URL always is request.url.path</li>
  291. <li><tt class="docutils literal"><span class="pre">cookies</span></tt> - StringTable of cookies.</li>
  292. </ul>
  293. <p><strong class="examples_text">Examples:</strong></p>
  294. <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">server</span> <span class="Other">=</span> <span class="Identifier">newServer</span><span class="Other">(</span><span class="Other">)</span>
  295. <span class="Identifier">server</span><span class="Other">.</span><span class="Identifier">pages</span><span class="Other">:</span>
  296. <span class="Identifier">equals</span><span class="Other">(</span><span class="StringLit">&quot;/home&quot;</span><span class="Other">)</span><span class="Other">:</span>
  297. <span class="Identifier">echo</span> <span class="Identifier">url</span>
  298. <span class="Identifier">echo</span> <span class="Identifier">urlParams</span>
  299. <span class="Identifier">await</span> <span class="Identifier">request</span><span class="Other">.</span><span class="Identifier">answer</span><span class="Other">(</span><span class="StringLit">&quot;Home&quot;</span><span class="Other">)</span>
  300. <span class="StringLit">&quot;/helloworld&quot;</span><span class="Other">:</span>
  301. <span class="Identifier">await</span> <span class="Identifier">request</span><span class="Other">.</span><span class="Identifier">answer</span><span class="Other">(</span><span class="StringLit">&quot;Hello, world&quot;</span><span class="Other">)</span></pre>
  302. </dd>
  303. <a id="send.m,untyped,untyped,HttpHeaders"></a>
  304. <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>
  305. <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>
  306. <dd>
  307. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  308. <p>Translates to</p>
  309. <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>
  310. <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>
  311. </dd>
  312. <a id="answer.m,untyped,untyped,HttpHeaders"></a>
  313. <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>
  314. <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>
  315. <dd>
  316. <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
  317. <p>Translates to</p>
  318. <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>
  319. <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>
  320. </dd>
  321. <a id="error.m,untyped,untyped,HttpHeaders"></a>
  322. <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>
  323. <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>
  324. <dd>
  325. <p>Responds from server with utf-8. Note: Content-length not automatically sends.</p>
  326. <p>Translates to</p>
  327. <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>
  328. <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>
  329. </dd>
  330. <a id="sendJson.m,untyped,untyped"></a>
  331. <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>
  332. <dd>
  333. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  334. <p>Translates to</p>
  335. <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>
  336. <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>
  337. </dd>
  338. <a id="sendPlaintext.m,untyped,untyped"></a>
  339. <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>
  340. <dd>
  341. <p>Sends JsonNode with &quot;Content-Type&quot;: &quot;application/json&quot; in headers. Note: Content-length does send automatically.</p>
  342. <p>Translates to</p>
  343. <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>
  344. <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>
  345. </dd>
  346. <a id="start.m,ServerRef"></a>
  347. <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>
  348. <dd>
  349. Starts server.
  350. <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>
  351. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">start</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  352. </dd>
  353. </dl></div>
  354. </div>
  355. </div>
  356. <div class="row">
  357. <div class="twelve-columns footer">
  358. <span class="nim-sprite"></span>
  359. <br/>
  360. <small style="color: var(--hint);">Made with Nim. Generated: 2020-06-21 09:56:01 UTC</small>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. </body>
  366. </html>