Description
Is your feature request related to a problem? Please describe.
I'm developing an HTTP API using Vapor where some endpoints may offer support for URL query parameters that have a key but no value (e.g. ?foo
vs ?foo=bar
). As far as I can tell, the URI Spec doesn't specify that query parameters must have a value, so my assumption was that this should be possible.
Describe the solution you'd like
It should be possible to decode query parameters and capture keys with no values:
var params: Dictionary<String, String?> = try req.query.decode(Dictionary<String, String?>.self)
Describe alternatives you've considered
This works as expected but it appears to skip query params with no values:
var params: Dictionary<String, String> = try req.query.decode(Dictionary<String, String>.self)
I've tried switching the Dictionary value type to an optional string and it still won't decode url query parameters without values
var params: Dictionary<String, String?> = try req.query.decode(Dictionary<String, String?>.self)
NOTE: I suspect a Struct attribute with an optional value would work, but I have not tried decoding to a struct because in my case I need support for dynamic query parameter keys, thus the Dictionary<String, String>
.
Additional context
Vapor appears to parse url params as long as there is an =
; so ?foo=
works, but ?foo
does not get parsed.
PS – I'm new to Vapor but I'm loving it so far! Keep up the great work! 💪
EDIT: added link to the URI Spec