diff --git a/http4sServer/src/main/scala/HttpRpcRoutes.scala b/http4sServer/src/main/scala/HttpRpcRoutes.scala index 3dde0f6a..9184f960 100644 --- a/http4sServer/src/main/scala/HttpRpcRoutes.scala +++ b/http4sServer/src/main/scala/HttpRpcRoutes.scala @@ -25,7 +25,7 @@ object HttpRpcRoutes { request.pathInfo.segments match { case Vector(traitName, methodName) => val method = sloth.Method(traitName.decoded(), methodName.decoded()) - val result = router(request).get(method).traverse { f => + val result = router(request).getMethod(method).traverse { f => request.as[PickleType].flatMap { payload => f(payload) match { case Left(error) => serverFailureToResponse[F](dsl, onError)(error) @@ -56,7 +56,7 @@ object HttpRpcRoutes { request.pathInfo.segments match { case Vector(traitName, methodName) => val method = sloth.Method(traitName.decoded(), methodName.decoded()) - val result = router(request).get(method).traverse { f => + val result = router(request).getMethod(method).traverse { f => request.as[String].flatMap { payload => f(payload) match { case Left(error) => serverFailureToResponse[F](dsl, onError)(error) diff --git a/sloth/src/main/scala/Router.scala b/sloth/src/main/scala/Router.scala index d850d6c5..759fa977 100644 --- a/sloth/src/main/scala/Router.scala +++ b/sloth/src/main/scala/Router.scala @@ -7,36 +7,36 @@ import cats.implicits._ import cats.~> trait Router[PickleType, Result[_]] { - val get: Router.ApiMapping[PickleType, Result] + val getMethod: Router.ApiMapping[PickleType, Result] def apply(request: Request[PickleType]): Either[ServerFailure, Result[PickleType]] = - get(request.method) match { + getMethod(request.method) match { case Some(function) => function(request.payload) case None => Left(ServerFailure.MethodNotFound(request.method)) } @deprecated("Use get(method) instead", "0.8.0") - def getFunction(path: List[String]): Option[PickleType => Either[ServerFailure, Result[PickleType]]] = get(Request.methodFromList(path)) + def getFunction(path: List[String]): Option[PickleType => Either[ServerFailure, Result[PickleType]]] = getMethod(Request.methodFromList(path)) def orElse(collect: Router.ApiMapping[PickleType, Result]): Router[PickleType, Result] } -class RouterCo[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val get: Router.ApiMapping[PickleType, Result])(implicit +class RouterCo[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val getMethod: Router.ApiMapping[PickleType, Result])(implicit private[sloth] val functor: Functor[Result] ) extends Router[PickleType, Result] with PlatformSpecificRouterCo[PickleType, Result] { - def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterCo[PickleType, Result] = new RouterCo(logger, request => get(request).orElse(collect(request))) + def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterCo[PickleType, Result] = new RouterCo(logger, request => getMethod(request).orElse(collect(request))) - def mapResult[R[_]: Functor](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterCo(logger, request => get(request).map { case v => v.map(_.map(f.apply)) }) + def mapResult[R[_]: Functor](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterCo(logger, request => getMethod(request).map { case v => v.map(_.map(f.apply)) }) } -class RouterContra[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val get: Router.ApiMapping[PickleType, Result])(implicit +class RouterContra[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val getMethod: Router.ApiMapping[PickleType, Result])(implicit private[sloth] val routerHandler: RouterContraHandler[Result] ) extends Router[PickleType, Result] with PlatformSpecificRouterContra[PickleType, Result] { - def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterContra[PickleType, Result] = new RouterContra(logger, request => get(request).orElse(collect(request))) + def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterContra[PickleType, Result] = new RouterContra(logger, request => getMethod(request).orElse(collect(request))) - def mapResult[R[_]: RouterContraHandler](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterContra(logger, request => get(request).map { case v => v.map(_.map(f.apply)) }) + def mapResult[R[_]: RouterContraHandler](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterContra(logger, request => getMethod(request).map { case v => v.map(_.map(f.apply)) }) } object Router {