michael at snoyman.com
Mon Apr 4 13:21:20 CEST 2011
There's an inherent difference in how Yesod handles routing, by default, and
how Happstack/Snap handle routing, by default. (Apologies if I am mistaken
in my understanding of the latter.) Yesod is built in with the concept of
type-safe URLs. This forms the basis of routing in Yesod: the list of path
segments is first converted to a type-safe URL value, and then the
appropriate handler is chosen from that. On the other hand, Happstack/Snap
both allow you to perform routing directly on the path segments.
What many people don't realize is that it's entirely possible to do
segment-based routing in Yesod. I don't recommend the practice in general,
since it defeats a lot of the type safety Yesod gives you. However, in some
situations it's a necessity. For example, yesod-auth allows arbitrary
authentication plugins, which would not mesh up well with type-safe URLs.
The trick to bypassing the type safety is to use multi-pieces. Instead of
describing how this is possible, I will merely point to an example:
The Yesod.Dynamic module defined there is really a general way to allow
Yesod routing based on path segments. Since the question has come up a
number of times in the past, I'm curious if people would want this available
on hackage. I'm sure a nice set of routing operators would be useful here as
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the web-devel