src/happyx/core/queries

Queries ❔

Provides working with query params

Procs

proc parseQuery(q: string): owned(StringTableRef) {....raises: [], tags: [],
    forbids: [].}
Parses query and retrieves StringTableRef object

Example:

import strtabs
let
  query = "a=1000&b=8000&password=mystrongpass"
  parsedQuery = parseQuery(query)
assert parsedQuery["a"] == "1000"
proc parseQueryArrays(query: string): TableRef[string, seq[string]] {.
    ...raises: [KeyError], tags: [], forbids: [].}
Parses query and retrieves TableRefstring, seq[string] object

Example:

import tables
let
  query = "a[]=10&a[]=100&a[]=foo&a[]=bar"
  parsedQuery = parseQueryArrays(query)
assert parsedQuery["a"] == @["10", "100", "foo", "bar"]

Macros

macro `?`(strTable: StringTableRef | TableRef[string, seq[string]]; key: untyped): untyped

Shortcut to get query param.

High-level API

Example

get "/":
  # exmple.com/?myParam=100
  echo query?myParam