{"action":"created","comment":{"url":"https://api.github.com/repos/finagle/finch/pulls/comments/24304997","id":24304997,"diff_hunk":"@@ -0,0 +1,46 @@\n+/*\n+ * Copyright 2014, by Vladimir Kostyukov and Contributors.\n+ *\n+ * This file is a part of a Finch library that may be found at\n+ *\n+ *      https://github.com/finagle/finch\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * You may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ *\n+ * Contributor(s):\n+ * Jens Halm\n+ */\n+package io.finch.request\n+\n+import org.scalatest.{Matchers, FlatSpec}\n+import com.twitter.util.{Future, Await}\n+import com.twitter.finagle.httpx.Request\n+import com.twitter.finagle.Service\n+import io.finch.HttpRequest\n+\n+class ReaderAsServiceSpec extends FlatSpec with Matchers {\n+\n+  \n+  \"A RequestReader\" should \"be usable as a Finagle Service\" in {\n+    case class MyRequest(request: HttpRequest)\n+    \n+    implicit def extractRequest(req: MyRequest): HttpRequest = req.request\n+    \n+    val request: MyRequest = MyRequest(Request((\"foo\", \"5\")))\n+    val reader: RequestReader[Int] = RequiredParam(\"foo\").as[Int]\n+    val service: Service[MyRequest, Int] = reader.asService[MyRequest]","path":"core/src/test/scala/io/finch/request/ReaderAsServiceSpec.scala","position":41,"original_position":41,"commit_id":"1cee39c3e2e4a5022be0688bc1a2dcde641b9c5c","original_commit_id":"1cee39c3e2e4a5022be0688bc1a2dcde641b9c5c","user":{"login":"vkostyukov","id":1098539,"avatar_url":"https://avatars.githubusercontent.com/u/1098539?v=3","gravatar_id":"","url":"https://api.github.com/users/vkostyukov","html_url":"https://github.com/vkostyukov","followers_url":"https://api.github.com/users/vkostyukov/followers","following_url":"https://api.github.com/users/vkostyukov/following{/other_user}","gists_url":"https://api.github.com/users/vkostyukov/gists{/gist_id}","starred_url":"https://api.github.com/users/vkostyukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkostyukov/subscriptions","organizations_url":"https://api.github.com/users/vkostyukov/orgs","repos_url":"https://api.github.com/users/vkostyukov/repos","events_url":"https://api.github.com/users/vkostyukov/events{/privacy}","received_events_url":"https://api.github.com/users/vkostyukov/received_events","type":"User","site_admin":false},"body":"Do you think it's possible to use an implicit conversion here instead of calling the `aService` method explicitly?","created_at":"2015-02-09T00:52:48Z","updated_at":"2015-02-09T00:52:48Z","html_url":"https://github.com/finagle/finch/pull/184#discussion_r24304997","pull_request_url":"https://api.github.com/repos/finagle/finch/pulls/184","_links":{"self":{"href":"https://api.github.com/repos/finagle/finch/pulls/comments/24304997"},"html":{"href":"https://github.com/finagle/finch/pull/184#discussion_r24304997"},"pull_request":{"href":"https://api.github.com/repos/finagle/finch/pulls/184"}}},"pull_request":{"url":"https://api.github.com/repos/finagle/finch/pulls/184","id":28889873,"html_url":"https://github.com/finagle/finch/pull/184","diff_url":"https://github.com/finagle/finch/pull/184.diff","patch_url":"https://github.com/finagle/finch/pull/184.patch","issue_url":"https://api.github.com/repos/finagle/finch/issues/184","number":184,"state":"open","locked":false,"title":"Allow a RequestReader to be used as a Finagle Service","user":{"login":"jenshalm","id":3116929,"avatar_url":"https://avatars.githubusercontent.com/u/3116929?v=3","gravatar_id":"","url":"https://api.github.com/users/jenshalm","html_url":"https://github.com/jenshalm","followers_url":"https://api.github.com/users/jenshalm/followers","following_url":"https://api.github.com/users/jenshalm/following{/other_user}","gists_url":"https://api.github.com/users/jenshalm/gists{/gist_id}","starred_url":"https://api.github.com/users/jenshalm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenshalm/subscriptions","organizations_url":"https://api.github.com/users/jenshalm/orgs","repos_url":"https://api.github.com/users/jenshalm/repos","events_url":"https://api.github.com/users/jenshalm/events{/privacy}","received_events_url":"https://api.github.com/users/jenshalm/received_events","type":"User","site_admin":false},"body":"In this case I might be missing something obvious which makes this PR obsolete. But I was wondering about the ways to combine a reader with Finagle Services and found examples like this in the documentation:\r\n\r\n```scala\r\nval user: RequestReader[User] = for {\r\n  name <- RequiredParam(\"name\")\r\n  age <- RequiredParam(\"age\").as[Int]\r\n  city <- OptionalParam(\"city\")\r\n} yield User(name, age, city.getOrElse(\"Novosibirsk\"))\r\n\r\nval service = new Service[HttpRequest, Json] {\r\n  def apply(req: HttpRequest) = for {\r\n    u <- user(req)\r\n  } yield Json.obj(\r\n    \"name\" -> u.name,\r\n    \"age\" -> u.age,\r\n    \"city\" -> u.city\r\n  )\r\n}\r\n```\r\n\r\nThis shows the use of a reader **inside** a service implementation. This is convenient for small and simple services, but for a bigger application I might prefer to have the reader itself as a pluggable service:\r\n\r\n```scala\r\ncase class MyRequest(request: HttpRequest)\r\n\r\nval userReader: RequestReader[User] = ???\r\n\r\nval userService: Service[MyRequest, User] = userReader.asService[MyRequest]\r\n\r\nval profileService: Service[User, UserProfile] = ???\r\n\r\nuserService ! profileService ! TurnIntoHttp[UserProfile]\r\n```\r\n\r\nThe reader becomes usable as a Finagle service through \"fixing\" the request type it can handle.\r\nThis way, apart from using the reader inside a service implementation, it can also be composed\r\nwith existing services that only deal with domain objects and not with anything HTTP.\r\n\r\nThis PR implements the `asService[Req]` method shown above.\r\n\r\nIs this a bad idea? Can the same be achieved by other means?\r\n\r\nIf this PR is seen as useful it would be cool to squeeze it into 0.5.0.","created_at":"2015-02-09T00:12:08Z","updated_at":"2015-02-09T00:52:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fd5e81ae1ec2aa0ac22ff20bac8ce5337e048587","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/finagle/finch/pulls/184/commits","review_comments_url":"https://api.github.com/repos/finagle/finch/pulls/184/comments","review_comment_url":"https://api.github.com/repos/finagle/finch/pulls/comments/{number}","comments_url":"https://api.github.com/repos/finagle/finch/issues/184/comments","statuses_url":"https://api.github.com/repos/finagle/finch/statuses/1cee39c3e2e4a5022be0688bc1a2dcde641b9c5c","head":{"label":"Sphonic:reader-as-service","ref":"reader-as-service","sha":"1cee39c3e2e4a5022be0688bc1a2dcde641b9c5c","user":{"login":"Sphonic","id":3746818,"avatar_url":"https://avatars.githubusercontent.com/u/3746818?v=3","gravatar_id":"","url":"https://api.github.com/users/Sphonic","html_url":"https://github.com/Sphonic","followers_url":"https://api.github.com/users/Sphonic/followers","following_url":"https://api.github.com/users/Sphonic/following{/other_user}","gists_url":"https://api.github.com/users/Sphonic/gists{/gist_id}","starred_url":"https://api.github.com/users/Sphonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sphonic/subscriptions","organizations_url":"https://api.github.com/users/Sphonic/orgs","repos_url":"https://api.github.com/users/Sphonic/repos","events_url":"https://api.github.com/users/Sphonic/events{/privacy}","received_events_url":"https://api.github.com/users/Sphonic/received_events","type":"Organization","site_admin":false},"repo":{"id":29857706,"name":"finch","full_name":"Sphonic/finch","owner":{"login":"Sphonic","id":3746818,"avatar_url":"https://avatars.githubusercontent.com/u/3746818?v=3","gravatar_id":"","url":"https://api.github.com/users/Sphonic","html_url":"https://github.com/Sphonic","followers_url":"https://api.github.com/users/Sphonic/followers","following_url":"https://api.github.com/users/Sphonic/following{/other_user}","gists_url":"https://api.github.com/users/Sphonic/gists{/gist_id}","starred_url":"https://api.github.com/users/Sphonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sphonic/subscriptions","organizations_url":"https://api.github.com/users/Sphonic/orgs","repos_url":"https://api.github.com/users/Sphonic/repos","events_url":"https://api.github.com/users/Sphonic/events{/privacy}","received_events_url":"https://api.github.com/users/Sphonic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Sphonic/finch","description":"Compose Finagle HTTP Services with Functional Programming","fork":true,"url":"https://api.github.com/repos/Sphonic/finch","forks_url":"https://api.github.com/repos/Sphonic/finch/forks","keys_url":"https://api.github.com/repos/Sphonic/finch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sphonic/finch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sphonic/finch/teams","hooks_url":"https://api.github.com/repos/Sphonic/finch/hooks","issue_events_url":"https://api.github.com/repos/Sphonic/finch/issues/events{/number}","events_url":"https://api.github.com/repos/Sphonic/finch/events","assignees_url":"https://api.github.com/repos/Sphonic/finch/assignees{/user}","branches_url":"https://api.github.com/repos/Sphonic/finch/branches{/branch}","tags_url":"https://api.github.com/repos/Sphonic/finch/tags","blobs_url":"https://api.github.com/repos/Sphonic/finch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sphonic/finch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sphonic/finch/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sphonic/finch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sphonic/finch/statuses/{sha}","languages_url":"https://api.github.com/repos/Sphonic/finch/languages","stargazers_url":"https://api.github.com/repos/Sphonic/finch/stargazers","contributors_url":"https://api.github.com/repos/Sphonic/finch/contributors","subscribers_url":"https://api.github.com/repos/Sphonic/finch/subscribers","subscription_url":"https://api.github.com/repos/Sphonic/finch/subscription","commits_url":"https://api.github.com/repos/Sphonic/finch/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sphonic/finch/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sphonic/finch/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sphonic/finch/issues/comments/{number}","contents_url":"https://api.github.com/repos/Sphonic/finch/contents/{+path}","compare_url":"https://api.github.com/repos/Sphonic/finch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sphonic/finch/merges","archive_url":"https://api.github.com/repos/Sphonic/finch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sphonic/finch/downloads","issues_url":"https://api.github.com/repos/Sphonic/finch/issues{/number}","pulls_url":"https://api.github.com/repos/Sphonic/finch/pulls{/number}","milestones_url":"https://api.github.com/repos/Sphonic/finch/milestones{/number}","notifications_url":"https://api.github.com/repos/Sphonic/finch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sphonic/finch/labels{/name}","releases_url":"https://api.github.com/repos/Sphonic/finch/releases{/id}","created_at":"2015-01-26T11:16:01Z","updated_at":"2015-02-07T11:01:22Z","pushed_at":"2015-02-09T00:50:09Z","git_url":"git://github.com/Sphonic/finch.git","ssh_url":"git@github.com:Sphonic/finch.git","clone_url":"https://github.com/Sphonic/finch.git","svn_url":"https://github.com/Sphonic/finch","homepage":"","size":1297,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"finagle:master","ref":"master","sha":"8e42d7e36700951b268d96527e2801fb13b574ad","user":{"login":"finagle","id":7944306,"avatar_url":"https://avatars.githubusercontent.com/u/7944306?v=3","gravatar_id":"","url":"https://api.github.com/users/finagle","html_url":"https://github.com/finagle","followers_url":"https://api.github.com/users/finagle/followers","following_url":"https://api.github.com/users/finagle/following{/other_user}","gists_url":"https://api.github.com/users/finagle/gists{/gist_id}","starred_url":"https://api.github.com/users/finagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/finagle/subscriptions","organizations_url":"https://api.github.com/users/finagle/orgs","repos_url":"https://api.github.com/users/finagle/repos","events_url":"https://api.github.com/users/finagle/events{/privacy}","received_events_url":"https://api.github.com/users/finagle/received_events","type":"Organization","site_admin":false},"repo":{"id":18798826,"name":"finch","full_name":"finagle/finch","owner":{"login":"finagle","id":7944306,"avatar_url":"https://avatars.githubusercontent.com/u/7944306?v=3","gravatar_id":"","url":"https://api.github.com/users/finagle","html_url":"https://github.com/finagle","followers_url":"https://api.github.com/users/finagle/followers","following_url":"https://api.github.com/users/finagle/following{/other_user}","gists_url":"https://api.github.com/users/finagle/gists{/gist_id}","starred_url":"https://api.github.com/users/finagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/finagle/subscriptions","organizations_url":"https://api.github.com/users/finagle/orgs","repos_url":"https://api.github.com/users/finagle/repos","events_url":"https://api.github.com/users/finagle/events{/privacy}","received_events_url":"https://api.github.com/users/finagle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/finagle/finch","description":"Purely Functional REST API atop of Finagle","fork":false,"url":"https://api.github.com/repos/finagle/finch","forks_url":"https://api.github.com/repos/finagle/finch/forks","keys_url":"https://api.github.com/repos/finagle/finch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/finagle/finch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/finagle/finch/teams","hooks_url":"https://api.github.com/repos/finagle/finch/hooks","issue_events_url":"https://api.github.com/repos/finagle/finch/issues/events{/number}","events_url":"https://api.github.com/repos/finagle/finch/events","assignees_url":"https://api.github.com/repos/finagle/finch/assignees{/user}","branches_url":"https://api.github.com/repos/finagle/finch/branches{/branch}","tags_url":"https://api.github.com/repos/finagle/finch/tags","blobs_url":"https://api.github.com/repos/finagle/finch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/finagle/finch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/finagle/finch/git/refs{/sha}","trees_url":"https://api.github.com/repos/finagle/finch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/finagle/finch/statuses/{sha}","languages_url":"https://api.github.com/repos/finagle/finch/languages","stargazers_url":"https://api.github.com/repos/finagle/finch/stargazers","contributors_url":"https://api.github.com/repos/finagle/finch/contributors","subscribers_url":"https://api.github.com/repos/finagle/finch/subscribers","subscription_url":"https://api.github.com/repos/finagle/finch/subscription","commits_url":"https://api.github.com/repos/finagle/finch/commits{/sha}","git_commits_url":"https://api.github.com/repos/finagle/finch/git/commits{/sha}","comments_url":"https://api.github.com/repos/finagle/finch/comments{/number}","issue_comment_url":"https://api.github.com/repos/finagle/finch/issues/comments/{number}","contents_url":"https://api.github.com/repos/finagle/finch/contents/{+path}","compare_url":"https://api.github.com/repos/finagle/finch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/finagle/finch/merges","archive_url":"https://api.github.com/repos/finagle/finch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/finagle/finch/downloads","issues_url":"https://api.github.com/repos/finagle/finch/issues{/number}","pulls_url":"https://api.github.com/repos/finagle/finch/pulls{/number}","milestones_url":"https://api.github.com/repos/finagle/finch/milestones{/number}","notifications_url":"https://api.github.com/repos/finagle/finch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/finagle/finch/labels{/name}","releases_url":"https://api.github.com/repos/finagle/finch/releases{/id}","created_at":"2014-04-15T12:17:44Z","updated_at":"2015-02-08T03:57:35Z","pushed_at":"2015-02-08T22:36:43Z","git_url":"git://github.com/finagle/finch.git","ssh_url":"git@github.com:finagle/finch.git","clone_url":"https://github.com/finagle/finch.git","svn_url":"https://github.com/finagle/finch","homepage":"http://finagle.github.io/finch/docs/#io.finch.route.package","size":3180,"stargazers_count":189,"watchers_count":189,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"open_issues_count":16,"forks":16,"open_issues":16,"watchers":189,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/finagle/finch/pulls/184"},"html":{"href":"https://github.com/finagle/finch/pull/184"},"issue":{"href":"https://api.github.com/repos/finagle/finch/issues/184"},"comments":{"href":"https://api.github.com/repos/finagle/finch/issues/184/comments"},"review_comments":{"href":"https://api.github.com/repos/finagle/finch/pulls/184/comments"},"review_comment":{"href":"https://api.github.com/repos/finagle/finch/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/finagle/finch/pulls/184/commits"},"statuses":{"href":"https://api.github.com/repos/finagle/finch/statuses/1cee39c3e2e4a5022be0688bc1a2dcde641b9c5c"}}}}