[web-devel] Re: ANNOUNCE: yesod 0.2.0

Matt Parker moonmaster9000 at gmail.com
Mon May 24 15:41:09 EDT 2010

i use type-safe urls all the time! in rails :-)

the rails router generates helper functions, allowing you to use route
helpers throughout your code instead of the literal urls - making it
possible, and simple, to change your routes throughout your entire codebase
by simply changing the route definition (assuming you actually used the
route helpers in your code instead of littering handcrafted url strings all
over the place).

if you've never seen it before, basically some code like this:

resources :blogs

generates url-generator methods like


where X=url or path

and also routes incoming requests to controller actions based on RESTful
conventions: GET /blogs would go to the BlogsController:#index action, GET
/blogs/1 would go to the BlogsController:#show action, POST /blogs/1 would
go to the BlogsController:#update action, etc. etc. there's also a lot of
other ways to specify routes (named routes, nested routes, default routes,
regular routes, etc)

On Mon, May 24, 2010 at 3:10 PM, Michael Snoyman <michael at snoyman.com>wrote:

> On Mon, May 24, 2010 at 8:49 PM, Gregory Collins <greg at gregorycollins.net>wrote:
>> Andrey Popp <8mayday at gmail.com> writes:
>> > Related to URL routing solutions in Yesod and Snap — I've found the
>> > Snap way to be more comfortable, maybe this is because the same syntax
>> > is used by Python/Ruby web frameworks (I personally have experience
>> > with many Python web frameworks). Also I don't think that URL routing
>> > type safety is also very important here.
>> There is actually nothing stopping us from providing a typesafe URL
>> routing engine; we just haven't done it yet because like you, it isn't
>> very important to us. Some people really like it though, so I can see us
>> providing something eventually.
>> I'm just curious if anyone's actually *used* type-safe URLs in production
> web apps. I'm not really aware of an implementation besides what Jeremy Shaw
> has done (first urlt and then web-routes). I'm afraid that the technique is
> not getting the credit it deserves.
> When I say type-safe URLs, I'm talking about having a datatype which
> represents all possible routes in an application, a function to convert from
> that datatype to a String, and a function to attempt converting a String to
> that datatype. As a simple example:
> data MyBlog = BlogHome | BlogEntry String | AtomFeed
> Then, instead of typing something like "/entries/" ++ entryName ++ "/", you
> just type BlogEntry entryName. In this simple case, it doesn't do much more
> than ensure you don't make typos.
> I can't go into details, but I had a project where I needed to change an
> entity relationship from  many-to-many to many-to-one, and suddenly I had to
> remove an extraneous parameter from all of my routes. Due to type-safe URLs,
> I changed the datatype and the compiler caught each and every time I needed
> to modify the code.
> More simply, if I decide suddenly to rename "/entry/1/" to "/post/1/", I
> only need to change the URL rendering function and all of my code is updated
> automatically.
> This monologue isn't meant as a Yesod-is-better-than-Snap, it's meant to
> point out that type-safe URLs are a very powerful feature, and I think it
> fits very nicely with the Haskell nature. I'd really urge people to look
> hard at them and consider using them.
> Michael
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/web-devel/attachments/20100524/1da1d8d9/attachment-0001.html

More information about the web-devel mailing list