Skip to content

Instantly share code, notes, and snippets.

@Miqueas
Created March 15, 2022 14:40
Show Gist options
  • Save Miqueas/f888d841a18d825b7993ce3bfc1e743d to your computer and use it in GitHub Desktop.
Save Miqueas/f888d841a18d825b7993ce3bfc1e743d to your computer and use it in GitHub Desktop.
[Nim] Simple operator for `Uri` to help append queries
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