[web-devel] WAI Routing
Stephen Paul Weber
singpolyma at singpolyma.net
Thu Aug 9 05:25:26 CEST 2012
I'm back! I've walked in the desert for a bit longer than last time I was
on this list, and have a much better handle on Haskell base concepts, which
is useful.
So, I re-looked-at yesod-routes as it exists now, and Yesod.Routes.Dispatch
is very nice for doing the sort of thing I want. Doesn't even use any
language extensions itself! (Oh, almost, it uses bang patterns. Or is that
not an extension when used in a datatype? Anyway...)
Unfortunately, using Yesod.Routes.Dispatch by itself is a bit verbose. Of
course, yesod-routes has all kinds of nice utilities to help with that, but
they are very TH-heavy, so I set out to build a different way: code
generation!
The result is: <http://hackage.haskell.org/package/route-generator> which
takes in a simple text file format (attoparsec FTW!) and outputs a module
that can be compiled into any application using yesod-routes and provide
a list of routes based on the text file. The types of the captured URI
segments are inferred from the types of the actual Haskell code that handles
the route.
The generator assumes a single module that it will import exports names for
all of the handlers, but I don't think this is too bad since you can always
have a module that just re-exports all the handlers from wherever you define
them.
A simple example is in the git repository.
I have also pushed up <http://hackage.haskell.org/package/wai-dispatch>,
which is a simple wrapper around Yesod.Routes.Dispatch for use in WAI apps
to convert a "default" (likely 404 or static file serving) Application, and
a list of Route for yesod-route, into an Application that does the routing.
It's very little code, but I immidiately identified it as code that would
end up appearing in every single one of my web apps, so I abstracted it out
into a tiny library.
--
Stephen Paul Weber, @singpolyma
See <http://singpolyma.net> for how I prefer to be contacted
edition right joseph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20120808/5d992ad5/attachment.pgp>
More information about the web-devel
mailing list