[web-devel] Re: Proposed changes to web-routes: query-string
michael at snoyman.com
Mon Aug 9 15:48:13 EDT 2010
On Mon, Aug 9, 2010 at 9:56 PM, Gregory Collins <greg at gregorycollins.net>wrote:
> Jeremy Shaw <jeremy at n-heptane.com> writes:
> > Nice!
> > I have not had time to look at this in detail, and probably won't for a
> > more days. But I am certainly in favor of the concept.
> > I recently wrote some code for one of my own projects to deal with
> > query string key/value pairs. It will be interesting to see how they
> > - jeremy
> > p.s. Also, the query string is not required to be key/value pairs. It can
> > any non-hierarchical data which, combined with the path info, serves to
> > identify a resource. It just happens the key/value pairs are the single
> > common what of encoding the this data. If web-routes is going to only
> > key/value pairs, that is fine. But we should probably acknowledge that
> in the
> > docs.
> Should the type of the query string part should be "[(String,[String])]"
> instead of "[(String, String)]"? I guess it depends on whether you
> wanted "/?foo=a&foo=b&foo=c" to decode the query params as:
> [("foo","a"), ("foo","b"), ("foo","c")]
> [("foo", ["a", "b", "c"])]
> The latter has the advantage that "lookup" returns all of the values at
> once. Would "Map String [String]" be better?
> I know that in practice we usually ignore the order of the keys, but in
theory that information could be useful. Also, I think that the [(String,
String)] is the most useful structure; if you want to get all the values,
just use a "filter (\x -> snd x == key)", and then the usual case of looking
up a single value is simple.
However, the most important issue is that the key/value pairs being
constructed here aren't actually being looked up in; it will almost
exclusively be used for constructing a URL, in which case this is the
simplest approach programatically. We also need to append lists, and having
the data type be [(String, [String])] would introduce a lot of overhead of
ensuring keys aren't duplicated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the web-devel