Created
November 25, 2015 16:22
-
-
Save kailuowang/98414e3b99a870ba0310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val endpoint0 = handle( | |
fromJson[PartialRequestMessage].body and from(req ⇒ 'name ->> req.headers("my_name") :: HNil), | |
process[RequestMessage] using myActor `then` expect[ResponseMessage].respondJson(Ok(_)) | |
) | |
val endPoint1 = handleParams( | |
process[RequestMessage] using myActor `then` expect[ResponseMessage].respond(Ok) `with` authentication | |
) | |
val endPoint2 = handle( | |
fromAuthorized(SessionInfo)(si ⇒ 'id ->> si.sessionId :: HNil), | |
process[RequestMessage] using myActor `then` expect[ResponseMessage].respondJson(Ok(_)) | |
) | |
val endPoint3 = handleParams( | |
process[RequestMessage] using myActor `then` | |
expect[ProcessResult].respondJson(Ok(_)).ifEmpty(_.content).respond(NotFound) | |
) | |
val endpoint = handleParams( | |
`with`(caching(3.hours) and authentication) { | |
process[RequestMsg] using actor `then` | |
(expect[ResponseMsg] respondJson (Ok(_)) `with` eTag(_.updated)) | |
} | |
) | |
both authentication and eTag are Filters which is
type Filter[-RMT] = (Request[RMT], ⇒ Future[Result]) ⇒ Future[Result]
The type (Symbol, T) doens't translate the value of the symbol into the type information, i.e. ('name, 1) and ('age, 2) are exactly the same type. I think the ->>
constructor from shapeless manage to convert the value of symbol into a singleton type. So I am not sure if it is achievable through the tuple values you suggested.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on a different note, having the users construct HLists would mean they'd have to include Shapeless in their codebase (include the library, add the necessary imports, etc) independent from the play-dsl library. or maybe that's not such a big deal.
I wonder if there's a way to have the
from
method to have an alternate version that accepts a functionRequest => Tuple
(of arbitrary size) and convert that to an HList. This way they could use built-in scala features to call it.e.g.,
where each element in the tuple is of type
(Symbol, T)
, which then gets converted to a record HList inside the play-dsl library. Not sure how much effort that would require (particularly, the part aboutfrom
accepting a tuple of arbitrary size/types)