Last active
August 29, 2015 14:14
-
-
Save pinge/d03f051b6d493ea98ef6 to your computer and use it in GitHub Desktop.
custom directives for extracting info from the request and logging
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
| trait ApiWithLoggingDirective extends HttpService { | |
| def clientIPOrLoopbackAddress: Directive1[RemoteAddress] = Directives.clientIP | provide(RemoteAddress("127.0.0.1")) | |
| def clientIPAndUri: Directive[RemoteAddress :: Uri :: HNil] = clientIPOrLoopbackAddress & requestUri | |
| def detachAndLogRequest: Directive0 = (detach(()) & clientIPAndUri).hflatMap { | |
| case (ip :: uri :: HNil) => RequestLog.requestLoggingDirective(ip, uri) | |
| } | |
| val playerTypes = (get & path("api" / "playerTypes")) { | |
| detachAndLogRequest() { | |
| complete { | |
| PlayerTypes.findAll | |
| } | |
| } | |
| } | |
| val article = (get & path("api" / "news" / LongNumber)) { articleId => | |
| detachAndLogRequest(Map("articleId" -> articleId.toString)) { | |
| complete { | |
| Article(articleId) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment