<?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);


  if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    document.documentElement.setAttribute('data-theme', "dark");
    toggleSwitch.checked = true;
  } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
    document.documentElement.setAttribute('data-theme', "light");
    toggleSwitch.checked = false;
  } else {
    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>
    &nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
  </div>
  <div id="global-links">
    <ul class="simple">
    </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>
</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"><wbr />Server<wbr />Ref<span class="attachedType"></span></a></li>

  </ul>
</li>
<li>
  <a class="reference reference-toplevel" href="#12" id="62">Procs</a>
  <ul class="simple simple-toc-section">
      <li><a class="reference" href="#newServer%2Cstring%2Cuint16"
    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>
  <li><a class="reference" href="#loadtemplate%2Cstring%2CJsonNode"
    title="loadtemplate(name: string; json: JsonNode = %*{}): Future[string]"><wbr />loadtemplate<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#parseQuery%2CRequest"
    title="parseQuery(request: Request): Future[JsonNode]"><wbr />parse<wbr />Query<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#password2hash%2Cstring"
    title="password2hash(password: string): Future[string]"><wbr />password2hash<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#validatePassword%2Cstring%2Cstring"
    title="validatePassword(password, hashpassword: string): Future[bool]"><wbr />validate<wbr />Password<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#newCookie%2CServerRef%2Cstring%2Cstring%2Cstring"
    title="newCookie(server: ServerRef; key, value: string; domain = &quot;&quot;): HttpHeaders"><wbr />new<wbr />Cookie<span class="attachedType">ServerRef</span></a></li>

  </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"><wbr />pages<span class="attachedType">ServerRef</span></a></li>
  <li><a class="reference" href="#answer.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
    title="answer(request, message: untyped; http_code = Http200;
       headers: HttpHeaders = newHttpHeaders()): untyped"><wbr />answer<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#error.m%2Cuntyped%2Cuntyped%2CHttpHeaders"
    title="error(request, message: untyped; http_code = Http404;
      headers: HttpHeaders = newHttpHeaders()): untyped"><wbr />error<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#sendJson.m%2Cuntyped%2Cuntyped"
    title="sendJson(request, message: untyped; http_code = Http200): untyped"><wbr />send<wbr />Json<span class="attachedType"></span></a></li>
  <li><a class="reference" href="#start.m%2CServerRef"
    title="start(server: ServerRef): untyped"><wbr />start<span class="attachedType">ServerRef</span></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">&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>

<span class="Identifier">my_sever</span><span class="Operator">.</span><span class="Identifier">pages</span><span class="Punctuation">:</span>
  <span class="StringLit">&quot;/&quot;</span><span class="Punctuation">:</span>
    <span class="Identifier">echo</span> <span class="StringLit">&quot;Index page&quot;</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">&quot;Hello, world!&quot;</span><span class="Punctuation">)</span>
  <span class="Identifier">notfound</span><span class="Punctuation">:</span>
    <span class="Identifier">echo</span> <span class="StringLit">&quot;oops :(&quot;</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">&quot;404 Page not found.&quot;</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="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">&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">
    <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. &quot;127.0.0.1&quot;</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">&quot;127.0.0.1&quot;</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="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>
<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. &quot;index&quot;, &quot;api&quot;, 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 -&gt; value</li>
<li>if @key { ... } -&gt; ... (if value is true)</li>
<li>if not @key { ... } -&gt; ... (if value is false)</li>
<li>for i in 0..@key { ... } -&gt; ........., etc</li>
<li>@key[0] -&gt; 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">&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>

</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="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>
<dd>

Decodes query.<dl class="docutils"><dt>e.g.:</dt>
<dd>&quot;a=5&amp;b=10&quot; -&gt; {&quot;a&quot;: &quot;5&quot;, &quot;b&quot;: &quot;10&quot;}</dd>
</dl>
<p>This also have debug output, if compiled in debug mode.</p>


</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="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>
<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>


</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="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>
<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>


</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">&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>
    <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>

</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">Examples:</strong></p>
<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>
<span class="Identifier">server</span><span class="Other">.</span><span class="Identifier">pages</span><span class="Other">:</span>
  <span class="Identifier">equals</span><span class="Other">(</span><span class="StringLit">&quot;/home&quot;</span><span class="Other">)</span><span class="Other">:</span>
    <span class="Identifier">echo</span> <span class="Identifier">url</span>
    <span class="Identifier">echo</span> <span class="Identifier">urlParams</span>
    <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>
  <span class="StringLit">&quot;/helloworld&quot;</span><span class="Other">:</span>
    <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>

</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.</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">&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>
<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>

</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.</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">&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>
<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>

</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 &quot;Content-Type&quot;: &quot;application/json&quot; in headers.</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">&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>
<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>

</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: 2020-06-01 11:11:23 UTC</small>
      </div>
    </div>
  </div>
</div>

</body>
</html>