On Sun, 2 Dec 2018 13:55:09 -0500, Steven Schveighoffer wrote:
On the server, when I get a GET query, the query parameters are in a
nice dictionary "query".
Let's say I have code in my diet template that I want to modify ONE of
those parameters, and generate a new query. This seemingly trivial task
has a lot of pitfalls!
I was wondering if vibe.d has a function to generate the query portion
of the GET request? It would be super-handy inside a diet template where
writing code and sub-functions isn't always easy.
Like for instance, let's say I have a url like so:
and then it maps to:
void getFoo(Nullable!int a, Nullable!string b, Nullable!float c)
Inside the diet template, using form controls or whatever, let's say I
want to modify only b, but then generate the updated url based on what
got passed in for a and c.
Anything that handles that?
A possibility is to modify the
req.query map and then use
vibe.inet.webform.formEncode to convert it back into a query string.
Unfortunately, there is a gap between the typed parameters in the web interface and the
query map - the REST interface generator generates similar query strings, but the code for that is private and the rules are partially different. So this part needs to be done by hand.
For reference, the exact inverse logic is in readFormParamRec. I guess it would be handy to have an API like
setWebParameter(M, T)(ref M map, string name, T value) that sets or replaces the matching value in an existing map with the properly converted value.