{"action":"created","issue":{"url":"https://api.github.com/repos/silkapp/rest/issues/98","labels_url":"https://api.github.com/repos/silkapp/rest/issues/98/labels{/name}","comments_url":"https://api.github.com/repos/silkapp/rest/issues/98/comments","events_url":"https://api.github.com/repos/silkapp/rest/issues/98/events","html_url":"https://github.com/silkapp/rest/issues/98","id":53240735,"number":98,"title":"rest-example: adding get handler to user resource?","user":{"login":"rvl","id":1019641,"avatar_url":"https://avatars.githubusercontent.com/u/1019641?v=3","gravatar_id":"","url":"https://api.github.com/users/rvl","html_url":"https://github.com/rvl","followers_url":"https://api.github.com/users/rvl/followers","following_url":"https://api.github.com/users/rvl/following{/other_user}","gists_url":"https://api.github.com/users/rvl/gists{/gist_id}","starred_url":"https://api.github.com/users/rvl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvl/subscriptions","organizations_url":"https://api.github.com/users/rvl/orgs","repos_url":"https://api.github.com/users/rvl/repos","events_url":"https://api.github.com/users/rvl/events{/privacy}","received_events_url":"https://api.github.com/users/rvl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-02T07:20:34Z","updated_at":"2015-01-02T16:59:25Z","closed_at":null,"body":"Hello, I was playing around with rest-example, trying to add a GET handler which looked up users by name. However, when I tried the URL http://localhost:3000/v1.0/user/erik, I got ``parseError: Failed to parse erik``. I'm not sure what I'm doing wrong. Any ideas? The diff follows...\r\n\r\n```patch\r\ndiff --git a/rest-example/example-api/Api/User.hs b/rest-example/example-api/Api/User.hs\r\nindex 584df5d..6839e38 100644\r\n--- a/rest-example/example-api/Api/User.hs\r\n+++ b/rest-example/example-api/Api/User.hs\r\n@@ -1,10 +1,10 @@\r\n module Api.User (resource) where\r\n \r\n import Control.Applicative ((<$>))\r\n-import Control.Concurrent.STM (atomically, modifyTVar, readTVar)\r\n+import Control.Concurrent.STM (STM, TVar, atomically, modifyTVar, readTVar)\r\n import Control.Monad.Error (ErrorT, throwError)\r\n import Control.Monad.Reader (ReaderT, asks)\r\n-import Control.Monad.Trans (liftIO)\r\n+import Control.Monad.Trans (lift, liftIO)\r\n import Data.Set (Set)\r\n import qualified Data.Foldable as F\r\n import qualified Data.Set      as Set\r\n@@ -28,11 +28,26 @@ type WithUser = ReaderT User.Name BlogApi\r\n resource :: Resource BlogApi WithUser User.Name () Void\r\n resource = mkResourceReader\r\n   { R.name   = \"user\" -- Name of the HTTP path segment.\r\n-  , R.schema = withListing () $ named [(\"name\", singleRead id)]\r\n+  , R.schema = withListing () $ unnamedSingleRead id\r\n   , R.list   = const list -- requested by GET /user, gives a paginated listing of users.\r\n   , R.create = Just create -- PUT /user creates a new user\r\n+  , R.get    = Just get -- GET /user/<name> retrieves one user\r\n   }\r\n \r\n+get :: Handler WithUser\r\n+get = mkIdHandler xmlJsonO handler\r\n+  where\r\n+    handler :: () -> User.Name -> ErrorT Reason_ WithUser User\r\n+    handler _ i = do\r\n+      mpost <- liftIO . atomically . userFromName i =<< (lift . lift) (asks users)\r\n+      case mpost of\r\n+        Nothing -> throwError NotFound\r\n+        Just a  -> return a\r\n+\r\n+userFromName :: User.Name -> TVar (Set User) -> STM (Maybe User)\r\n+userFromName ident pv = finder <$> readTVar pv\r\n+  where finder = F.find ((== ident) . User.name) . Set.toList\r\n+\r\n list :: ListHandler BlogApi\r\n```\r\n\r\nCheers."},"comment":{"url":"https://api.github.com/repos/silkapp/rest/issues/comments/68542058","html_url":"https://github.com/silkapp/rest/issues/98#issuecomment-68542058","issue_url":"https://api.github.com/repos/silkapp/rest/issues/98","id":68542058,"user":{"login":"hesselink","id":75477,"avatar_url":"https://avatars.githubusercontent.com/u/75477?v=3","gravatar_id":"","url":"https://api.github.com/users/hesselink","html_url":"https://github.com/hesselink","followers_url":"https://api.github.com/users/hesselink/followers","following_url":"https://api.github.com/users/hesselink/following{/other_user}","gists_url":"https://api.github.com/users/hesselink/gists{/gist_id}","starred_url":"https://api.github.com/users/hesselink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hesselink/subscriptions","organizations_url":"https://api.github.com/users/hesselink/orgs","repos_url":"https://api.github.com/users/hesselink/repos","events_url":"https://api.github.com/users/hesselink/events{/privacy}","received_events_url":"https://api.github.com/users/hesselink/received_events","type":"User","site_admin":false},"created_at":"2015-01-02T16:59:25Z","updated_at":"2015-01-02T16:59:25Z","body":"When you say `unnamedSingleRead`, it will use `Read` to parse the url string (`erik`) into the identifier type (`User.Name`, which is a type synonym for `Text`). The `Read` instance for `Text` (like that for `String`) requires double quotes. What you probably want to do instead is use `unnamedSingle T.pack`.\r\n\r\nPlease let me know if this works (I've just read your code, not tried to compile this). If it does, I think the original example code should also be changed to `singleBy T.pack`."}}