Skip to content

Instantly share code, notes, and snippets.

@Yardanico

Yardanico/tt.nim Secret

Created August 1, 2020 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yardanico/6457d94ed01c5af17a5bc3810c21e5ea to your computer and use it in GitHub Desktop.
Save Yardanico/6457d94ed01c5af17a5bc3810c21e5ea to your computer and use it in GitHub Desktop.
import std/json
import std/algorithm
type
EncodedHeaders* = tuple[signed: string; canonical: string]
KeyValue = tuple[key: string; val: string]
proc encodedQuery(input: openArray[KeyValue]): string =
## encoded a series of key/value pairs as a query string
echo input
let query = input.sortedByIt((it.key, it.val))
echo query
proc encodedQuery(node: JsonNode): string =
var query: seq[KeyValue]
for q in node.pairs:
query.add (key: "hello", val: $q.val)
echo repr query
result = encodedQuery(query)
var cq = newJObject()
cq["a"] = newJInt(1)
cq["b"] = newJInt(2)
let enc = cq.encodedQuery()
echo enc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment