Reputation: 1371
I see repeating code like following in many methods in a play contorller. since request is available in the Actions, any way to abstract this out of all the methods to avoid repetation?
def serveData = Action { implicit request =>
val host = "http://" + request.host
Upvotes: 1
Views: 34
Reputation: 23881
You can do something like this:
def withHost(f: String => SimpleResult) = Action { implicit request =>
val host = "http://" + request.host
f(host)
}
def serveData = withHost { host =>
Ok(host)
}
Upvotes: 1