본문 바로가기

Development/Web & Server

[Play Framework] Request Handler 처리 방법


Play Framework 2.4버전 처리 방법이다 (https://www.playframework.com/documentation/2.4.x/ScalaHttpRequestHandlers)


import javax.inject.Inject
import play.api.http._
import play.api.mvc._
import play.api.routing.Router

class SimpleHttpRequestHandler @Inject() (router: Router) extends HttpRequestHandler {
  def handlerForRequest(request: RequestHeader) = {
    router.routes.lift(request) match {
      case Some(handler) => (request, handler)
      case None => (request, Action(Results.NotFound))
    }
  }
}