PgRest.Request.QueryString (PgRest v0.3.0)

Copy Markdown View Source

Parses a raw query string into an ordered list of {key, value} pairs.

Pairs split on & and ; (as PostgREST does). Order and duplicate keys are preserved (a=1&a=2 stays two pairs), + decodes to a space, and malformed percent-encoding is a 400 rather than an exception.

A key with no = (?id) has a nil value, while ?id= has "". PostgREST ignores the former and parses the latter as a filter (400), so consumers drop nil-valued pairs.

Differences from PostgREST

Malformed percent escapes return PGRST100 rather than being tolerated.

Summary

Functions

Splits on & or ;, then the first =, decoding both sides.

Functions

parse(query_string)

@spec parse(binary()) ::
  {:ok, [{String.t(), String.t() | nil}]} | {:error, PgRest.Error.t()}

Splits on & or ;, then the first =, decoding both sides.