Wednesday, August 29, 2012

Processing *.csv file in lift

Lift dispatch uses a Req to match a request with a response, so if you want to process the request send to the path /foo/bar.html, you can have the request:

case Req("foo" :: "bar" ::  _, "html", GetRequest)       => returnTheResponse()

Now, it would seems normal, if you want to return a csv file (request /foo/bar.csv), you would do something like this:

case Req("foo" :: "bar" ::  _, "csv", GetRequest)       => returnTheCSVResponse()

I've banged my head a long time and went into the source to find out why my request was never processed. I finally found help in this Thread , lift only parse a set of suffix, and csv is not part of it. To add it, one just need to add in boot:

LiftRules.explicitlyParsedSuffixes += "csv"

No comments:

Post a Comment