Files
Nim/uri.html
github-actions[bot] ef3d9e7b38 Deploy to GitHub pages
2025-12-28 15:55:52 +00:00

570 lines
68 KiB
HTML

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>std/uri</title>
<!-- 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'/>
<!-- 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=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
<!-- JS -->
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">std/uri</h1>
<div class="row">
<div class="three columns">
<div class="theme-select-wrapper">
<label for="theme-select">Theme:&nbsp;</label>
<select id="theme-select" onchange="setTheme(this.value)">
<option value="auto">🌗 Match OS</option>
<option value="dark">🌑 Dark</option>
<option value="light">🌕 Light</option>
</select>
</div>
<div id="global-links">
<ul class="simple-boot">
<li><a href="manual.html">Manual</a></li>
<li><a href="lib.html">Standard library</a></li>
<li> <a id="indexLink" href="theindex.html">Index</a></li>
<li><a href="compiler/theindex.html">Compiler docs</a></li>
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="search" id="searchInput"
oninput="search()" />
</div>
<ul class="simple simple-toc" id="toc-list">
<li><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic usage</a></li>
<ul class="simple"><li><a class="reference" id="basic-usage-combine-uris_toc" href="#basic-usage-combine-uris">Combine URIs</a></li>
<li><a class="reference" id="basic-usage-access-uri-item_toc" href="#basic-usage-access-uri-item">Access URI item</a></li>
<li><a class="reference" id="basic-usage-data-uri-base64_toc" href="#basic-usage-data-uri-base64">Data URI Base64</a></li>
</ul><li>
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#Uri" title="Uri = object
scheme*, username*, password*: string
hostname*, port*, path*, query*, anchor*: string
opaque*: bool
isIpv6*: bool">Uri</a></li>
<li><a class="reference" href="#UriParseError" title="UriParseError = object of ValueError">UriParseError</a></li>
<li><a class="reference" href="#Url" title="Url = distinct string">Url</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">$
<li><a class="reference" href="#%24%2CUri" title="`$`(u: Uri): string">`$`(u: Uri): string</a></li>
</ul>
<ul class="simple nested-toc-section">/
<li><a class="reference" href="#%2F%2CUri%2Cstring" title="`/`(x: Uri; path: string): Uri">`/`(x: Uri; path: string): Uri</a></li>
</ul>
<ul class="simple nested-toc-section">?
<li><a class="reference" href="#%3F%2CUri%2CopenArray%5B%5D" title="`?`(u: Uri; query: openArray[(string, string)]): Uri">`?`(u: Uri; query: openArray[(string, string)]): Uri</a></li>
</ul>
<ul class="simple nested-toc-section">combine
<li><a class="reference" href="#combine%2CUri%2CUri" title="combine(base: Uri; reference: Uri): Uri">combine(base: Uri; reference: Uri): Uri</a></li>
<li><a class="reference" href="#combine%2Cvarargs%5BUri%5D" title="combine(uris: varargs[Uri]): Uri">combine(uris: varargs[Uri]): Uri</a></li>
</ul>
<ul class="simple nested-toc-section">decodeUrl
<li><a class="reference" href="#decodeUrl%2Cstring" title="decodeUrl(s: string; decodePlus = true): string">decodeUrl(s: string; decodePlus = true): string</a></li>
</ul>
<ul class="simple nested-toc-section">encodeQuery
<li><a class="reference" href="#encodeQuery%2CopenArray%5B%5D%2Cchar" title="encodeQuery(query: openArray[(string, string)]; usePlus = true; omitEq = true;
sep = '&amp;'): string">encodeQuery(query: openArray[(string, string)]; usePlus = true; omitEq = true;
sep = '&amp;'): string</a></li>
</ul>
<ul class="simple nested-toc-section">encodeUrl
<li><a class="reference" href="#encodeUrl%2Cstring" title="encodeUrl(s: string; usePlus = true): string">encodeUrl(s: string; usePlus = true): string</a></li>
</ul>
<ul class="simple nested-toc-section">getDataUri
<li><a class="reference" href="#getDataUri%2Cstring%2Cstring%2Cstring" title="getDataUri(data, mime: string; encoding = &quot;utf-8&quot;): string">getDataUri(data, mime: string; encoding = &quot;utf-8&quot;): string</a></li>
</ul>
<ul class="simple nested-toc-section">initUri
<li><a class="reference" href="#initUri" title="initUri(isIpv6 = false): Uri">initUri(isIpv6 = false): Uri</a></li>
</ul>
<ul class="simple nested-toc-section">isAbsolute
<li><a class="reference" href="#isAbsolute%2CUri" title="isAbsolute(uri: Uri): bool">isAbsolute(uri: Uri): bool</a></li>
</ul>
<ul class="simple nested-toc-section">parseUri
<li><a class="reference" href="#parseUri%2Cstring" title="parseUri(uri: string): Uri">parseUri(uri: string): Uri</a></li>
<li><a class="reference" href="#parseUri%2Cstring%2CUri" title="parseUri(uri: string; result: var Uri)">parseUri(uri: string; result: var Uri)</a></li>
</ul>
<ul class="simple nested-toc-section">uriParseError
<li><a class="reference" href="#uriParseError%2Cstring" title="uriParseError(msg: string)">uriParseError(msg: string)</a></li>
</ul>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">decodeQuery
<li><a class="reference" href="#decodeQuery.i%2Cstring%2Cchar" title="decodeQuery(data: string; sep = '&amp;'): tuple[key, value: string]">decodeQuery(data: string; sep = '&amp;'): tuple[key, value: string]</a></li>
</ul>
</ul>
</details>
</li>
</ul>
</div>
<div class="nine columns" id="content">
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
<div id="tocRoot"></div>
<p class="module-desc"><p>This module implements URI parsing as specified by RFC 3986.</p>
<p>A Uniform Resource Identifier (URI) provides a simple and extensible means for identifying a resource. A URI can be further classified as a locator, a name, or both. The term &quot;Uniform Resource Locator&quot; (URL) refers to the subset of URIs.</p>
<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
URI parsers in this module do not perform security validation.</div>
<h1><a class="toc-backref" id="basic-usage" href="#basic-usage">Basic usage</a></h1>
<h2><a class="toc-backref" id="basic-usage-combine-uris" href="#basic-usage-combine-uris">Combine URIs</a></h2>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">uri</span>
<span class="Keyword">let</span> <span class="Identifier">host</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">host</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org&quot;</span>
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">host</span> <span class="Operator">/</span> <span class="StringLit">&quot;/blog.html&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org/blog.html&quot;</span>
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">host</span> <span class="Operator">/</span> <span class="StringLit">&quot;blog2.html&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org/blog2.html&quot;</span></pre>
<h2><a class="toc-backref" id="basic-usage-access-uri-item" href="#basic-usage-access-uri-item">Access URI item</a></h2>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">uri</span>
<span class="Keyword">let</span> <span class="Identifier">res</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;sftp://127.0.0.1:4343&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">isAbsolute</span><span class="Punctuation">(</span><span class="Identifier">res</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">port</span> <span class="Operator">==</span> <span class="StringLit">&quot;4343&quot;</span></pre>
<h2><a class="toc-backref" id="basic-usage-data-uri-base64" href="#basic-usage-data-uri-base64">Data URI Base64</a></h2>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">uri</span>
<span class="Identifier">assert</span> <span class="Identifier">getDataUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;text/plain&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;data:text/plain;charset=utf-8;base64,SGVsbG8gV29ybGQ=&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">getDataUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;Nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;text/plain&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;data:text/plain;charset=utf-8;base64,Tmlt&quot;</span></pre></p>
<div class="section" id="6">
<h1><a class="toc-backref" href="#6">Imports</a></h1>
<dl class="item">
<a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="parseutils.html">parseutils</a>, <a class="reference external" href="base64.html">base64</a>, <a class="reference external" href="since.html">since</a>, <a class="reference external" href="decode_helpers.html">decode_helpers</a>, <a class="reference external" href="assertions.html">assertions</a>
</dl>
</div>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="Uri">
<dt><pre><a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">scheme</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">username</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">password</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
<span class="Identifier">hostname</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">port</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">path</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">query</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">anchor</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
<span class="Identifier">opaque</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a>
<span class="Identifier">isIpv6</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
<dd>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L51" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L51" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="UriParseError">
<dt><pre><a href="uri.html#UriParseError"><span class="Identifier">UriParseError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a></pre></dt>
<dd>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L57" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L57" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="Url">
<dt><pre><a href="uri.html#Url"><span class="Identifier">Url</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
<dd>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L49" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L49" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</dl>
</div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="$-procs-all">
<div id="$,Uri">
<dt><pre><span class="Keyword">func</span> <a href="#%24%2CUri"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">u</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the string representation of the specified URI object.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L496" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L496" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="/-procs-all">
<div id="/,Uri,string">
<dt><pre><span class="Keyword">func</span> <a href="#%2F%2CUri%2Cstring"><span class="Identifier">`/`</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">;</span> <span class="Identifier">path</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Concatenates the path specified to the specified URIs path.</p>
<p>Contrary to the <a class="reference external" href="#combine,Uri,Uri">combine func</a> you do not have to worry about the slashes at the beginning and end of the path and URIs path respectively.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#combine,Uri,Uri">combine func</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">foo</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar&quot;</span><span class="Punctuation">)</span> <span class="Operator">/</span> <span class="StringLit">&quot;/baz&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">foo</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/foo/bar/baz&quot;</span>
<span class="Keyword">let</span> <span class="Identifier">bar</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar&quot;</span><span class="Punctuation">)</span> <span class="Operator">/</span> <span class="StringLit">&quot;baz&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">bar</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/foo/bar/baz&quot;</span>
<span class="Keyword">let</span> <span class="Identifier">qux</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar/&quot;</span><span class="Punctuation">)</span> <span class="Operator">/</span> <span class="StringLit">&quot;baz&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">qux</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/foo/bar/baz&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L454" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L454" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="?-procs-all">
<div id="?,Uri,openArray[]">
<dt><pre><span class="Keyword">func</span> <a href="#%3F%2CUri%2CopenArray%5B%5D"><span class="Identifier">`?`</span></a><span class="Other">(</span><span class="Identifier">u</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">;</span> <span class="Identifier">query</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Concatenates the query parameters to the specified URI object.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">foo</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://example.com&quot;</span><span class="Punctuation">)</span> <span class="Operator">/</span> <span class="StringLit">&quot;foo&quot;</span> <span class="Operator">?</span> <span class="Punctuation">{</span><span class="StringLit">&quot;bar&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;qux&quot;</span><span class="Punctuation">}</span>
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">foo</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://example.com/foo?bar=qux&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L488" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L488" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="combine-procs-all">
<div id="combine,Uri,Uri">
<dt><pre><span class="Keyword">func</span> <a href="#combine%2CUri%2CUri"><span class="Identifier">combine</span></a><span class="Other">(</span><span class="Identifier">base</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">;</span> <span class="Identifier">reference</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Combines a base URI with a reference URI.</p>
<p>This uses the algorithm specified in <a class="reference external" href="https://tools.ietf.org/html/rfc3986#section-5.2.2">section 5.2.2 of RFC 3986</a>.</p>
<p>This means that the slashes inside the base URIs path as well as reference URIs path affect the resulting URI.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#/,Uri,string">/ func</a> for building URIs</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">foo</span> <span class="Operator">=</span> <span class="Identifier">combine</span><span class="Punctuation">(</span><span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;/baz&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">foo</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/baz&quot;</span>
<span class="Keyword">let</span> <span class="Identifier">bar</span> <span class="Operator">=</span> <span class="Identifier">combine</span><span class="Punctuation">(</span><span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;baz&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">bar</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/foo/baz&quot;</span>
<span class="Keyword">let</span> <span class="Identifier">qux</span> <span class="Operator">=</span> <span class="Identifier">combine</span><span class="Punctuation">(</span><span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/foo/bar/&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;baz&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">qux</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/foo/bar/baz&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L382" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L382" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="combine,varargs[Uri]">
<dt><pre><span class="Keyword">func</span> <a href="#combine%2Cvarargs%5BUri%5D"><span class="Identifier">combine</span></a><span class="Other">(</span><span class="Identifier">uris</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Combines multiple URIs together.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#/,Uri,string">/ func</a> for building URIs</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">foo</span> <span class="Operator">=</span> <span class="Identifier">combine</span><span class="Punctuation">(</span><span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;docs/&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span>
<span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;manual.html&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">foo</span><span class="Operator">.</span><span class="Identifier">hostname</span> <span class="Operator">==</span> <span class="StringLit">&quot;nim-lang.org&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">foo</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/docs/manual.html&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L433" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L433" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="decodeUrl-procs-all">
<div id="decodeUrl,string">
<dt><pre><span class="Keyword">func</span> <a href="#decodeUrl%2Cstring"><span class="Identifier">decodeUrl</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">decodePlus</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Decodes a URL according to RFC3986.</p>
<p>This means that any <tt class="docutils literal"><span class="pre"><span class="Operator">%</span><span class="Identifier">xx</span></span></tt> (where <tt class="docutils literal"><span class="pre"><span class="Identifier">xx</span></span></tt> denotes a hexadecimal value) are converted to the character with ordinal number <tt class="docutils literal"><span class="pre"><span class="Identifier">xx</span></span></tt>, and every other character is carried over. If <tt class="docutils literal"><span class="pre"><span class="Identifier">xx</span></span></tt> is not a valid hexadecimal value, it is left intact.</p>
<p>As a special rule, when the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">decodePlus</span></span></tt> is true, <tt class="docutils literal"><span class="pre"><span class="Operator">+</span></span></tt> characters are converted to a space.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#encodeUrl,string">encodeUrl func</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">decodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">decodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org%2Fthis+is+a+test&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org/this is a test&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">decodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org%2Fthis%20is%20a%20test&quot;</span><span class="Punctuation">,</span>
<span class="Identifier">false</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https://nim-lang.org/this is a test&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">decodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;abc%xyz&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;abc%xyz&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L93" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L93" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="encodeQuery-procs-all">
<div id="encodeQuery,openArray[],char">
<dt><pre><span class="Keyword">func</span> <a href="#encodeQuery%2CopenArray%5B%5D%2Cchar"><span class="Identifier">encodeQuery</span></a><span class="Other">(</span><span class="Identifier">query</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">usePlus</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
<span class="Identifier">omitEq</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span> <span class="Identifier">sep</span> <span class="Other">=</span> <span class="CharLit">'&amp;'</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Encodes a set of (key, value) parameters into a URL query string.</p>
<p>Every (key, value) pair is URL-encoded and written as <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span><span class="Operator">=</span><span class="Identifier">value</span></span></tt>. If the value is an empty string then the <tt class="docutils literal"><span class="pre"><span class="Operator">=</span></span></tt> is omitted, unless <tt class="docutils literal"><span class="pre"><span class="Identifier">omitEq</span></span></tt> is false. The pairs are joined together by the <tt class="docutils literal"><span class="pre"><span class="Identifier">sep</span></span></tt> character.</p>
<p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">usePlus</span></span></tt> parameter is passed down to the <tt class="docutils literal"><span class="pre"><span class="Identifier">encodeUrl</span></span></tt> function that is used for the URL encoding of the string values.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#encodeUrl,string">encodeUrl func</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">encodeQuery</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="Punctuation">:</span> <span class="Punctuation">}</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">encodeQuery</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;2&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;a=1&amp;b=2&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">encodeQuery</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;a=1&amp;b&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">encodeQuery</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">}</span><span class="Punctuation">,</span> <span class="Identifier">omitEq</span> <span class="Operator">=</span> <span class="Identifier">false</span><span class="Punctuation">,</span> <span class="Identifier">sep</span> <span class="Operator">=</span> <span class="CharLit">';'</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;a=1;b=&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L130" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L130" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="encodeUrl-procs-all">
<div id="encodeUrl,string">
<dt><pre><span class="Keyword">func</span> <a href="#encodeUrl%2Cstring"><span class="Identifier">encodeUrl</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">usePlus</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Encodes a URL according to RFC3986.</p>
<p>This means that characters in the set <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">'..'</span><span class="Identifier">z</span><span class="CharLit">', '</span><span class="Identifier">A</span><span class="CharLit">'..'</span><span class="Identifier">Z</span><span class="CharLit">', '</span><span class="DecNumber">0'</span><span class="Operator">..</span><span class="CharLit">'9'</span><span class="Punctuation">,</span> <span class="CharLit">'-'</span><span class="Punctuation">,</span> <span class="CharLit">'.'</span><span class="Punctuation">,</span> <span class="CharLit">'_'</span><span class="Punctuation">,</span> <span class="CharLit">'~'</span><span class="Punctuation">}</span></span></tt> are carried over to the result. All other characters are encoded as <tt class="docutils literal"><span class="pre"><span class="Operator">%</span><span class="Identifier">xx</span></span></tt> where <tt class="docutils literal"><span class="pre"><span class="Identifier">xx</span></span></tt> denotes its hexadecimal value.</p>
<p>As a special rule, when the value of <tt class="docutils literal"><span class="pre"><span class="Identifier">usePlus</span></span></tt> is true, spaces are encoded as <tt class="docutils literal"><span class="pre"><span class="Operator">+</span></span></tt> instead of <tt class="docutils literal"><span class="pre"><span class="Operator">%</span><span class="DecNumber">20</span></span></tt>.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#decodeUrl,string">decodeUrl func</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">encodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">encodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/this is a test&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org%2Fthis+is+a+test&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">encodeUrl</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/this is a test&quot;</span><span class="Punctuation">,</span> <span class="Identifier">false</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;https%3A%2F%2Fnim-lang.org%2Fthis%20is%20a%20test&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L64" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L64" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="getDataUri-procs-all">
<div id="getDataUri,string,string,string">
<dt><pre><span class="Keyword">proc</span> <a href="#getDataUri%2Cstring%2Cstring%2Cstring"><span class="Identifier">getDataUri</span></a><span class="Other">(</span><span class="Identifier">data</span><span class="Other">,</span> <span class="Identifier">mime</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">encoding</span> <span class="Other">=</span> <span class="StringLit">&quot;utf-8&quot;</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Convenience proc for <tt class="docutils literal"><span class="pre"><span class="Identifier">base64</span><span class="Operator">.</span><span class="Identifier">encode</span></span></tt> returns a standard Base64 Data URI (RFC-2397)</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="mimetypes.html">mimetypes</a> for <tt class="docutils literal"><span class="pre"><span class="Identifier">mime</span></span></tt> argument</li>
<li><a class="reference external" href="https://tools.ietf.org/html/rfc2397">https://tools.ietf.org/html/rfc2397</a></li>
<li><a class="reference external" href="https://en.wikipedia.org/wiki/Data_URI_scheme">https://en.wikipedia.org/wiki/Data_URI_scheme</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">static</span><span class="Punctuation">:</span> <span class="Identifier">assert</span> <span class="Identifier">getDataUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;Nim&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;text/plain&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;data:text/plain;charset=utf-8;base64,Tmlt&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L556" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L556" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="initUri-procs-all">
<div id="initUri">
<dt><pre><span class="Keyword">func</span> <a href="#initUri"><span class="Identifier">initUri</span></a><span class="Other">(</span><span class="Identifier">isIpv6</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Initializes a URI with <tt class="docutils literal"><span class="pre"><span class="Identifier">scheme</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">username</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">password</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">hostname</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">port</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">path</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">query</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">anchor</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">isIpv6</span></span></tt>.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#Uri">Uri type</a> for available fields in the URI type</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">uri2</span> <span class="Operator">=</span> <span class="Identifier">initUri</span><span class="Punctuation">(</span><span class="Identifier">isIpv6</span> <span class="Operator">=</span> <span class="Identifier">true</span><span class="Punctuation">)</span>
<span class="Identifier">uri2</span><span class="Operator">.</span><span class="Identifier">scheme</span> <span class="Operator">=</span> <span class="StringLit">&quot;tcp&quot;</span>
<span class="Identifier">uri2</span><span class="Operator">.</span><span class="Identifier">hostname</span> <span class="Operator">=</span> <span class="StringLit">&quot;2001:0db8:85a3:0000:0000:8a2e:0370:7334&quot;</span>
<span class="Identifier">uri2</span><span class="Operator">.</span><span class="Identifier">port</span> <span class="Operator">=</span> <span class="StringLit">&quot;8080&quot;</span>
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">uri2</span> <span class="Operator">==</span> <span class="StringLit">&quot;tcp://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L250" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L250" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="isAbsolute-procs-all">
<div id="isAbsolute,Uri">
<dt><pre><span class="Keyword">func</span> <a href="#isAbsolute%2CUri"><span class="Identifier">isAbsolute</span></a><span class="Other">(</span><span class="Identifier">uri</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns true if URI is absolute, false otherwise.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isAbsolute</span>
<span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim-lang&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isAbsolute</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L447" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L447" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="parseUri-procs-all">
<div id="parseUri,string">
<dt><pre><span class="Keyword">func</span> <a href="#parseUri%2Cstring"><span class="Identifier">parseUri</span></a><span class="Other">(</span><span class="Identifier">uri</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Parses a URI and returns it.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#Uri">Uri type</a> for available fields in the URI type</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">res</span> <span class="Operator">=</span> <span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;ftp://Username:Password@Hostname&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">username</span> <span class="Operator">==</span> <span class="StringLit">&quot;Username&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">password</span> <span class="Operator">==</span> <span class="StringLit">&quot;Password&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">scheme</span> <span class="Operator">==</span> <span class="StringLit">&quot;ftp&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L320" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L320" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="parseUri,string,Uri">
<dt><pre><span class="Keyword">func</span> <a href="#parseUri%2Cstring%2CUri"><span class="Identifier">parseUri</span></a><span class="Other">(</span><span class="Identifier">uri</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">result</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Parses a URI. The <tt class="docutils literal"><span class="pre"><span class="Identifier">result</span></span></tt> variable will be cleared before.</p>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="#Uri">Uri type</a> for available fields in the URI type</li>
<li><a class="reference external" href="#initUri">initUri func</a> for initializing a URI</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">res</span> <span class="Operator">=</span> <span class="Identifier">initUri</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Identifier">parseUri</span><span class="Punctuation">(</span><span class="StringLit">&quot;https://nim-lang.org/docs/manual.html&quot;</span><span class="Punctuation">,</span> <span class="Identifier">res</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">scheme</span> <span class="Operator">==</span> <span class="StringLit">&quot;https&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">hostname</span> <span class="Operator">==</span> <span class="StringLit">&quot;nim-lang.org&quot;</span>
<span class="Identifier">assert</span> <span class="Identifier">res</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/docs/manual.html&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L272" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L272" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="uriParseError-procs-all">
<div id="uriParseError,string">
<dt><pre><span class="Keyword">proc</span> <a href="#uriParseError%2Cstring"><span class="Identifier">uriParseError</span></a><span class="Other">(</span><span class="Identifier">msg</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span class="Identifier">noreturn</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">UriParseError</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 class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Raises a <tt class="docutils literal"><span class="pre"><span class="Identifier">UriParseError</span></span></tt> exception with message <tt class="docutils literal"><span class="pre"><span class="Identifier">msg</span></span></tt>.
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L60" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L60" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
<div class="section" id="15">
<h1><a class="toc-backref" href="#15">Iterators</a></h1>
<dl class="item">
<div id="decodeQuery-iterators-all">
<div id="decodeQuery.i,string,char">
<dt><pre><span class="Keyword">iterator</span> <a href="#decodeQuery.i%2Cstring%2Cchar"><span class="Identifier">decodeQuery</span></a><span class="Other">(</span><span class="Identifier">data</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sep</span> <span class="Other">=</span> <span class="CharLit">'&amp;'</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</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 class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Reads and decodes the query string <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> and yields the <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> pairs the data consists of. If compiled with <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">nimLegacyParseQueryStrict</span></span></tt>, a <tt class="docutils literal"><span class="pre"><span class="Identifier">UriParseError</span></span></tt> is raised when there is an unencoded <tt class="docutils literal"><span class="pre"><span class="Operator">=</span></span></tt> character in a decoded value, which was the behavior in Nim &lt; 1.5.1.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span>
<span class="Identifier">assert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">decodeQuery</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo=1&amp;bar=2=3&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;bar&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2=3&quot;</span><span class="Punctuation">)</span><span class="Punctuation">]</span>
<span class="Identifier">assert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">decodeQuery</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo=1;bar=2=3&quot;</span><span class="Punctuation">,</span> <span class="CharLit">';'</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;bar&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2=3&quot;</span><span class="Punctuation">)</span><span class="Punctuation">]</span>
<span class="Identifier">assert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">decodeQuery</span><span class="Punctuation">(</span><span class="StringLit">&quot;&amp;a&amp;=b&amp;=&amp;&amp;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">)</span><span class="Punctuation">]</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/uri.nim#L160" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/uri.nim#L160" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-28 15:54:56 UTC</small>
</div>
</div>
</div>
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
</body>
</html>