123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!-- Favicon -->
- <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=="/>
- <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=">
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- CSS -->
- <title>akane</title>
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css">
- <script type="text/javascript" src="dochack.js"></script>
- <script type="text/javascript">
- function main() {
- var pragmaDots = document.getElementsByClassName("pragmadots");
- for (var i = 0; i < pragmaDots.length; i++) {
- pragmaDots[i].onclick = function(event) {
- // Hide tease
- event.target.parentNode.style.display = "none";
- // Show actual
- event.target.parentNode.nextElementSibling.style.display = "inline";
- }
- }
- const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
- function switchTheme(e) {
- if (e.target.checked) {
- document.documentElement.setAttribute('data-theme', 'dark');
- localStorage.setItem('theme', 'dark');
- } else {
- document.documentElement.setAttribute('data-theme', 'light');
- localStorage.setItem('theme', 'light');
- }
- }
- toggleSwitch.addEventListener('change', switchTheme, false);
- const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
- if (currentTheme) {
- document.documentElement.setAttribute('data-theme', currentTheme);
- if (currentTheme === 'dark') {
- toggleSwitch.checked = true;
- }
- }
- }
- </script>
- </head>
- <body onload="main()">
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">akane</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-switch-wrapper">
- <label class="theme-switch" for="checkbox">
- <input type="checkbox" id="checkbox" />
- <div class="slider round"></div>
- </label>
- <em>Dark Mode</em>
- </div>
- <div id="global-links">
- <ul class="simple">
- <li>
- <a href="theindex.html">Index</a>
- </li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="text" id="searchInput"
- onkeyup="search()" />
- </div>
- <div>
- Group by:
- <select onchange="groupBy(this.value)">
- <option value="section">Section</option>
- <option value="type">Type</option>
- </select>
- </div>
- <ul class="simple simple-toc" id="toc-list">
- <ul class="simple"><li><a class="reference" id="simple-usage_toc" href="#simple-usage">Simple usage</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- <li><a class="reference" id="example_toc" href="#example">Example</a></li>
- </ul><li>
- <a class="reference reference-toplevel" href="#7" id="57">Types</a>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#ServerRef"
- title="ServerRef = ref object
- port*: uint16
- address*: string
- server*: AsyncHttpServer">ServerRef</a></li>
- </ul>
- </li>
- <li>
- <a class="reference reference-toplevel" href="#10" id="60">Consts</a>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#AnyHttpMethod"
- title="AnyHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete, HttpTrace,
- HttpOptions, HttpConnect, HttpPatch]">AnyHttpMethod</a></li>
- <li><a class="reference" href="#BaseHttpMethod"
- title="BaseHttpMethod = [HttpHead, HttpGet, HttpPost, HttpPut, HttpDelete]">BaseHttpMethod</a></li>
- </ul>
- </li>
- <li>
- <a class="reference reference-toplevel" href="#12" id="62">Procs</a>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">newServer
- <li><a class="reference" href="#newServer%2Cstring%2Cuint16"
- title="newServer(address: string = "127.0.0.1"; port: uint16 = 5000): ServerRef">newServer,<wbr>string,<wbr>uint16</a></li>
- </ul>
- <ul class="simple nested-toc-section">validatePassword
- <li><a class="reference" href="#validatePassword%2Cstring%2Cstring"
- title="validatePassword(password, hashpassword: string): Future[bool]">validatePassword,<wbr>string,<wbr>string</a></li>
- </ul>
- <ul class="simple nested-toc-section">parseQuery
- <li><a class="reference" href="#parseQuery%2CRequest"
- title="parseQuery(request: Request): Future[JsonNode]">parseQuery,<wbr>Request</a></li>
- </ul>
- <ul class="simple nested-toc-section">loadtemplate
- <li><a class="reference" href="#loadtemplate%2Cstring%2CJsonNode"
- title="loadtemplate(name: string; json: JsonNode = %*{}): Future[string]">loadtemplate,<wbr>string,<wbr>JsonNode</a></li>
- </ul>
- <ul class="simple nested-toc-section">newCookie
- <li><a class="reference" href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"
- title="newCookie(server: ServerRef; key, value: string; domain = ""): HttpHeaders">newCookie,<wbr>ServerRef,<wbr>string,<wbr>string,<wbr>string</a></li>
- </ul>
- <ul class="simple nested-toc-section">password2hash
- <li><a class="reference" href="#password2hash%2Cstring"
- title="password2hash(password: string): Future[string]">password2hash,<wbr>string</a></li>
- </ul>
- </ul>
- </li>
- <li>
- <a class="reference reference-toplevel" href="#17" id="67">Macros</a>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#pages.m%2CServerRef%2Cuntyped"
- title="pages(server: ServerRef; body: untyped): untyped">pages</a></li>
- <li><a class="reference" href="#send.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
- title="send(request, message: untyped; http_code = Http200;
- headers: HttpHeaders = newHttpHeaders()): untyped">send</a></li>
- <li><a class="reference" href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
- title="answer(request, message: untyped; http_code = Http200;
- headers: HttpHeaders = newHttpHeaders()): untyped">answer</a></li>
- <li><a class="reference" href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
- title="error(request, message: untyped; http_code = Http404;
- headers: HttpHeaders = newHttpHeaders()): untyped">error</a></li>
- <li><a class="reference" href="#sendJson.m%2Cuntyped%2Cuntyped"
- title="sendJson(request, message: untyped; http_code = Http200): untyped">sendJson</a></li>
- <li><a class="reference" href="#sendPlaintext.m%2Cuntyped%2Cuntyped"
- title="sendPlaintext(request, message: untyped; http_code = Http200): untyped">sendPlaintext</a></li>
- <li><a class="reference" href="#start.m%2CServerRef"
- title="start(server: ServerRef): untyped">start</a></li>
- </ul>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <div id="tocRoot"></div>
-
- <p class="module-desc">
- <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">"127.0.0.1"</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>
- <span class="Identifier">my_sever</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span>
- <span class="StringLit">"/"</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span> <span class="StringLit">"Index page"</span>
- <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">"Hello, world!"</span><span class="Punctuation">)</span>
- <span class="Identifier">notfound</span><span class="Punctuation">:</span>
- <span class="Identifier">echo</span> <span class="StringLit">"oops :("</span>
- <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">"404 Page not found."</span><span class="Punctuation">)</span></pre></p>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <a id="ServerRef"></a>
- <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>
- <span class="Identifier">port</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">uint16</span>
- <span class="Identifier">address</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span>
- <span class="Identifier">server</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">AsyncHttpServer</span>
- </pre></dt>
- <dd>
- </dd>
- </dl></div>
- <div class="section" id="10">
- <h1><a class="toc-backref" href="#10">Consts</a></h1>
- <dl class="item">
- <a id="AnyHttpMethod"></a>
- <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>
- <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>
- <dd>
- </dd>
- <a id="BaseHttpMethod"></a>
- <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>
- <dd>
- </dd>
- </dl></div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <a id="newServer,string,uint16"></a>
- <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">"127.0.0.1"</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">
- <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>
- <dd>
- <p>Creates a new ServerRef object.</p>
- <p>Arguments:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">address</span></tt> - server address, e.g. "127.0.0.1"</li>
- <li><tt class="docutils literal"><span class="pre">port</span></tt> - server port, e.g. 5000</li>
- </ul>
- <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">"127.0.0.1"</span><span class="Punctuation">,</span> <span class="DecNumber">5000</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="loadtemplate,string,JsonNode"></a>
- <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>
- <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>
- <dd>
- <p>Loads HTML template from <tt class="docutils literal"><span class="pre">templates</span></tt> folder.</p>
- <p>Arguments:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">name</span></tt> - template's name, e.g. "index", "api", etc.</li>
- <li><tt class="docutils literal"><span class="pre">json</span></tt> - Json data, which replaces in the template.</li>
- </ul>
- <p>Replaces:</p>
- <ul class="simple"><li>@key -> value</li>
- <li>if @key { ... } -> ... (if value is true)</li>
- <li>if not @key { ... } -> ... (if value is false)</li>
- <li>for i in 0..@key { ... } -> ........., etc</li>
- <li>@key[0] -> key[0]</li>
- </ul>
- <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">"index.html"</span><span class="Punctuation">,</span> <span class="Operator">%*</span><span class="Punctuation">{</span><span class="StringLit">"a"</span><span class="Punctuation">:</span> <span class="DecNumber">5</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="parseQuery,Request"></a>
- <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">
- <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>
- <dd>
- Decodes query.<dl class="docutils"><dt>e.g.:</dt>
- <dd>"a=5&b=10" -> {"a": "5", "b": "10"}</dd>
- </dl>
- <p>This also have debug output, if compiled in debug mode.</p>
- </dd>
- <a id="newCookie,ServerRef,string,string,string"></a>
- <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">""</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> <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>
- <dd>
- <p>Creates a new cookies</p>
- <p>Arguments:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">key</span></tt> is a cookie key.</li>
- <li><tt class="docutils literal"><span class="pre">value</span></tt> is a new cookie value.</li>
- <li><tt class="docutils literal"><span class="pre">domain</span></tt> is a cookie doomain.</li>
- </ul>
- </dd>
- <a id="password2hash,string"></a>
- <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>
- <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>
- <dd>
- <p>Generates a sha1 from <tt class="docutils literal"><span class="pre">password</span></tt>.</p>
- <p>Arguments:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is an user password.</li>
- </ul>
- <p>WARNING! It's works only with <tt class="docutils literal"><span class="pre">-d:tools</span></tt>.</p>
- </dd>
- <a id="validatePassword,string,string"></a>
- <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>
- <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>
- <dd>
- <p>Validates the password and returns true, if the password is valid.</p>
- <p>Arguments:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">password</span></tt> is a got password from user input.</li>
- <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>
- </ul>
- <p>WARNING! It's works only with <tt class="docutils literal"><span class="pre">-d:tools</span></tt>.</p>
- </dd>
- </dl></div>
- <div class="section" id="17">
- <h1><a class="toc-backref" href="#17">Macros</a></h1>
- <dl class="item">
- <a id="pages.m,ServerRef,untyped"></a>
- <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>
- <dd>
- <p>This macro provides convenient page adding.</p>
- <p><tt class="docutils literal"><span class="pre">body</span></tt> should be StmtList. page type can be:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">equals</span></tt></li>
- <li><tt class="docutils literal"><span class="pre">startswith</span></tt></li>
- <li><tt class="docutils literal"><span class="pre">endswith</span></tt></li>
- <li><tt class="docutils literal"><span class="pre">regex</span></tt> - match url via regex.</li>
- <li><tt class="docutils literal"><span class="pre">notfound</span></tt> - this page uses without URL argument.</li>
- </ul>
- <p>When a new request to the server is received, variables are automatically created:</p>
- <ul class="simple"><li><tt class="docutils literal"><span class="pre">request</span></tt> - new Request.</li>
- <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>
- <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>
- <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>
- <li><tt class="docutils literal"><span class="pre">regex</span></tt> - URL is matched text.</li>
- <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>
- </ul>
- </li>
- <li><tt class="docutils literal"><span class="pre">urlParams</span></tt> - query URL (in JSON).</li>
- <li><tt class="docutils literal"><span class="pre">decoded_url</span></tt> - URL always is request.url.path</li>
- <li><tt class="docutils literal"><span class="pre">cookies</span></tt> - StringTable of cookies.</li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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">
- </span><span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span><span class="Whitespace">
- </span><span class="Identifier">equals</span><span class="Punctuation">(</span><span class="StringLit">"/home"</span><span class="Punctuation">)</span><span class="Punctuation">:</span><span class="Whitespace">
- </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">url</span><span class="Whitespace">
- </span><span class="Identifier">echo</span><span class="Whitespace"> </span><span class="Identifier">urlParams</span><span class="Whitespace">
- </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">"Home"</span><span class="Punctuation">)</span><span class="Whitespace">
- </span><span class="Comment"># You can also not write `equals("/")`:</span><span class="Whitespace">
- </span><span class="StringLit">"/helloworld"</span><span class="Punctuation">:</span><span class="Whitespace">
- </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">"Hello, world"</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="send.m,untyped,untyped,HttpHeaders"></a>
- <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>
- <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>
- <dd>
- <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
- <p>Translates to</p>
- <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>
- <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">"hello!"</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="answer.m,untyped,untyped,HttpHeaders"></a>
- <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>
- <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>
- <dd>
- <p>Responds from server with utf-8. Note: Content-length does not send automatically.</p>
- <p>Translates to</p>
- <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">"<head><meta charset='utf-8'></head>"</span> <span class="Operator">&</span> <span class="Identifier">message</span><span class="Punctuation">,</span> <span class="Identifier">headers</span><span class="Punctuation">)</span></pre>
- <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">"hello!"</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="error.m,untyped,untyped,HttpHeaders"></a>
- <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>
- <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>
- <dd>
- <p>Responds from server with utf-8. Note: Content-length not automatically sends.</p>
- <p>Translates to</p>
- <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">"<head><meta charset='utf-8'></head>"</span> <span class="Operator">&</span> <span class="Identifier">message</span><span class="Punctuation">)</span></pre>
- <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">"Oops! :("</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="sendJson.m,untyped,untyped"></a>
- <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>
- <dd>
- <p>Sends JsonNode with "Content-Type": "application/json" in headers. Note: Content-length does send automatically.</p>
- <p>Translates to</p>
- <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">"Content-Type"</span><span class="Punctuation">,</span><span class="StringLit">"application/json"</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
- <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">"response"</span><span class="Punctuation">:</span> <span class="StringLit">"error"</span><span class="Punctuation">,</span> <span class="StringLit">"msg"</span><span class="Punctuation">:</span> <span class="StringLit">"oops :("</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="sendPlaintext.m,untyped,untyped"></a>
- <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>
- <dd>
- <p>Sends JsonNode with "Content-Type": "application/json" in headers. Note: Content-length does send automatically.</p>
- <p>Translates to</p>
- <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">"Content-Type"</span><span class="Punctuation">,</span><span class="StringLit">"plain/text"</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
- <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">"response"</span><span class="Punctuation">:</span> <span class="StringLit">"error"</span><span class="Punctuation">,</span> <span class="StringLit">"msg"</span><span class="Punctuation">:</span> <span class="StringLit">"oops :("</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre>
- </dd>
- <a id="start.m,ServerRef"></a>
- <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>
- <dd>
- Starts server.
- <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>
- <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">start</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
- </dd>
- </dl></div>
- </div>
- </div>
- <div class="row">
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br/>
- <small style="color: var(--hint);">Made with Nim. Generated: 2023-03-29 07:13:26 UTC</small>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
|