Created
March 15, 2022 14:40
-
-
Save Miqueas/f888d841a18d825b7993ce3bfc1e743d to your computer and use it in GitHub Desktop.
[Nim] Simple operator for `Uri` to help append queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std/uri | |
proc `?+`*(url: Uri, ql: openArray[tuple[string, string]]): Uri = | |
var qs = @ql | |
if url.query.len() != 0: | |
for k, v in url.query.decodeQuery(): | |
qs.add( (k, v) ) | |
return url ? qs | |
proc `?+=`*(url: var Uri, ql: openArray[tuple[string, string]]) {.inline.} = url = url ?+ ql | |
var url = parseUri("https://example.org?x=y") | |
echo url | |
url ?+= { "a": "b" } | |
echo url | |
echo url ?+ { "e": "h" } | |
echo url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment