Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to shortcut adding handlers to Yesod?

I'm just starting out in Haskell and Yesod. To get my feet wet, I'm going to convert a small project that I wrote in MVC into Haskell. My first step was just to get all the routes defined.

All told, I have 8 handlers to make this project run. My routes file looks like this:

/activity ActivityR GET
/activity/#String ActivityItemR POST DELETE

/dashboard/month MonthDashboardR GET
/dashboard/year YearDashboardR GET

/calendar CalendarR GET

/events/calendar CalendarEventsR GET
/events/report ReportEventsR GET

/report ReportR GET

The flow I went through in adding these routes went like this:

  1. Add route to config/routes
  2. Create file in Handler folder (I created one for each route parent, e.g. /events or /dashboard)
  3. Add an import to the handler created in step #2 to Application.hs
  4. Add the handler file name to my project's cabal file

Is there a shortcut, or way to wildcard these handlers so that I could do something like Import Handler.*

Or is the preferred way to have fewer handler modules that handle multiple different routes?

like image 821
taylonr Avatar asked Jul 01 '13 02:07

taylonr


1 Answers

The yesod command line tool provides the command add-handler which will automate much of this.

like image 170
Michael Snoyman Avatar answered Nov 15 '22 08:11

Michael Snoyman