A Nim library for parsing RFC 3986 URL query strings.
Types
httpParam {.final.} = object
httpQuery {.final.} = object
HTTPQueryException {.pure, inheritable.} = object of CatchableError
HTTPQueryParseException {.pure, inheritable.} = object of HTTPQueryException
Procs
proc `=destroy`(query: httpQuery): void {....raises: [], tags: [], forbids: [].}
- Destructor. Automatically frees the internal query resources.
proc dumpString(query: httpQuery): string {....raises: [], tags: [], forbids: [].}
- Serializes the query back into a query string (e.g. "key1=value1&..."). The returned string is properly encoded.
proc getItem(query: httpQuery; index: int): hquery_param_t {....raises: [], tags: [], forbids: [].}
- Returns the raw hquery_param_t at the given index (0-based).
proc getString(param: httpParam; key: string; decode: bool = true): string {. ...raises: [KeyError], tags: [], forbids: [].}
-
Retrieves a string value by key from a single httpParam.
- If decode is true (default), the value is URL-decoded.
proc getString(query: httpQuery; key: string; decode: bool = true): string {. ...raises: [KeyError], tags: [], forbids: [].}
-
Retrieves a string value by key from the query.
- If decode is true (default), the value is URL-decoded.
- With duplicate keys, the first match is returned.
- Key matching follows setIgnoreCase.
proc loadEnviron(query: httpQuery): void {....raises: [HTTPQueryParseException], tags: [], forbids: [].}
-
Loads the process environment into the query.
Environment variable names are case-sensitive. This resets the query and its options before loading.
proc newHttpQuery(sep: char = '&'; subsep: string = "="): httpQuery {. ...raises: [], tags: [], forbids: [].}
-
Creates a new empty httpQuery object.
- sep: character used to separate parameters (default &).
- subsep: string used to separate key from value (default =).
proc parseString(query: httpQuery; str: string): void {. ...raises: [HTTPQueryParseException], tags: [], forbids: [].}
-
Parses a query string (e.g. "key1=value1&key2=value2") into the httpQuery object.
Duplicate keys in the input are preserved.
proc setDuplicates(query: var httpQuery; enabled: bool = true): void {. ...raises: [], tags: [], forbids: [].}
-
Enables or disables duplicate keys.
When enabled, adding a key that already exists appends a new parameter instead of replacing the existing value. Lookups return the first match.
proc setIgnoreCase(query: var httpQuery; enabled: bool = true): void {. ...raises: [], tags: [], forbids: [].}
-
Enables or disables case-insensitive key lookups.
When enabled, lookups and add* procedures match keys without regard to case. The original key casing is preserved.