[web-devel] Re: Proposed changes to web-routes: query-string support

Michael Snoyman 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
> few
> > 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
> creating
> > query string key/value pairs. It will be interesting to see  how they
> overlap.
> >
> > - jeremy
> >
> > p.s. Also, the query string is not required to be key/value pairs. It can
> be
> > 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
> most
> > common what of encoding the this data. If web-routes  is going to only
> support
> > 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")]
> vs
>    [("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...
URL: http://www.haskell.org/pipermail/web-devel/attachments/20100809/4770c43e/attachment.html

More information about the web-devel mailing list