buildQueryParamsEncoded
fn
string buildQueryParamsEncoded(T)(T pairs, bool spaceAsPlus = false) if (is(T : Tuple!(string, string)[])) @safeBuild a percent-encoded query string from key/value pairs.
Encodes keys and values per RFC 3986 Component.Query. When spaceAsPlus is true, spaces (U+0020) are serialized as `+` and literal pluses are serialized as %2B, emulating application/x-www-form-urlencoded.
Parameters
pairs | Array of (key, value) tuples. |
spaceAsPlus | If true, serialize spaces as `+`. |
Returns
A query string without the leading `?`.
Examples
import std.typecons : tuple;
auto p = [ tuple("q", "hello world +"), tuple("u", "€") ];
assert(buildQueryParamsEncoded(p, false) == "q=hello%20world%20+&u=%E2%82%AC");
assert(buildQueryParamsEncoded(p, true) == "q=hello+world+%2B&u=%E2%82%AC");