Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Created April 3, 2018 22:18
Show Gist options
  • Save richdougherty/a8df0e8406035ad0a4ba728274bedc72 to your computer and use it in GitHub Desktop.
Save richdougherty/a8df0e8406035ad0a4ba728274bedc72 to your computer and use it in GitHub Desktop.
Exploring more flexible handlers in Play
trait Handler
trait HandlerOp[+A]
case class HandlerVal[+A](value: A) extends HandlerOp[A]
case class HandlerThunk[+A](thunk: () => A) extends HandlerOp[A]
case class HandlerFuture[+A](future: Future[A]) extends HandlerOp[A]
case class HandlerEither[+A,B<:A,C<:A](either: Either[B,C]) extends HandlerOp[A]
object Handler {
trait RequestHeader
case class PlayRequestHeader(rh: play.api.mvc.RequestHeader) extends RequestHandler
trait Request
case class PlayRequest[A](req: play.api.mvc.Request[A]) extends Request
case class AkkaHttpRequest(req: HttpRequest) extends Request
trait Response
case class PlayResult(resp: Result) extends Response
case class AkkaHttpResponse(resp: HttpResponse) extends Response
}
trait RequestHandler extends Handler
case class RequestHandlerOp(op: HandlerOp[RequestHandler]) extends RequestHandler
case class HeaderHandler(f: Handler.RequestHeader => HandlerOp[RequestHandler]) extends RequestHandler
case class RawRequestHandler(raw: Any => HandlerOp[ResponseHandler]) extends RequestHandler
case class
case class
case class ActionHandler(acc: Accumulator[ByteString, HandlerOp[RequestHandler]]) extends RequestHandler
trait ResponseHandler extends RequestHandler
case object UnhandledResponseHandler extends ResponseHandler
case class ResultResponse(res: Result) extends ResponseHandler
case class ResponseHandlerThunk(thunk: () => ResponseHandler) extends ResponseHandler
case class FutureResponseHandler(fut: Future[ResponseHandler]) extends ResponseHandler
case class RawResponseHandler(response: Any) extends ResponseHandler
case class RawAkkaHttpHandler(f: HttpRequest => Future[HttpResponse]) extends Handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment