apiGetResource :: FromJSON res
               => (ref -> String) -- ^ Function to build the /ref/ parameter of the request
               -> String          -- ^ Endpoint, e.g. "/users"
               -> URI             -- ^ The base URL of the database, e.g. http://localhost:1337
               -> ref             -- ^ The reference to the
               -> IO (Either String res)
apiGetResource mkRefParam frag baseUrl ref = do
  let endpoint = baseUrl
        { uriPath  = uriPath baseUrl ++ frag
        , uriQuery = "?ref=" ++ mkRefParam ref
        }
      req :: Request BSL.ByteString
      req = mkRequest GET endpoint
  eresp <- simpleHTTP req
  return $ case eresp of
    Left err   -> Left $ "Error from HTTP: " ++ show err
    Right resp ->
      let mRes = decode $ rspBody resp
      in case mRes of
        Nothing  -> Left "Can't parse the JSON response"
        Just res -> Right res
apiGetResource :: FromJSON res
               => (ref -> String) -- ^ Function to build the /ref/ parameter of the request
               -> String          -- ^ Endpoint, e.g. "/users"
               -> URI             -- ^ The base URL of the database, e.g. http://localhost:1337
               -> ref             -- ^ The reference to the
               -> IO (Either String res)
apiGetResource mkRefParam frag baseUrl ref = do
  let endpoint = baseUrl
        { uriPath  = uriPath baseUrl ++ frag
        , uriQuery = "?ref=" ++ mkRefParam ref
        }
      req :: Request BSL.ByteString
      req = mkRequest GET endpoint
  eresp <- simpleHTTP req
  return $ case eresp of
    Left err   -> Left $ "Error from HTTP: " ++ show err
    Right resp ->
      let mRes = decode $ rspBody resp
      in case mRes of
        Nothing  -> Left "Can't parse the JSON response"
        Just res -> Right res
apiGetResource mkRefParam frag baseUrl ref = do
  let endpoint = baseUrl
        { uriPath  = uriPath baseUrl ++ frag
        , uriQuery = "?ref=" ++ mkRefParam ref
        }
      req :: Request BSL.ByteString
      req = mkRequest GET endpoint
  eresp <- simpleHTTP req
  return $ case eresp of
    Left err   -> Left $ "Error from HTTP: " ++ show err
    Right resp ->
      let mRes = decode $ rspBody resp
      in case mRes of
        Nothing  -> Left "Can't parse the JSON response"
        Just res -> Right res