Simplify app with a do block

This commit is contained in:
Joe Nelson
2014-07-13 10:31:47 -07:00
parent 919d827b24
commit a28553dd45
+12 -8
View File
@@ -44,14 +44,18 @@ main = do
describe = progDesc "create a REST API to an existing Postgres database"
app :: AppConfig -> Application
app config req respond =
case path of
[] -> respond =<< responseLBS status200 [json] <$> (printTables =<< conn)
[table] -> respond =<< (<$>) (responseLBS status200 [json])
( if verb == methodOptions
then printColumns table =<< conn
else selectWhere table qq =<< conn )
_ -> respond $ responseLBS status404 [] ""
app config req respond = do
r <-
case path of
[] -> responseLBS status200 [json] <$> (printTables =<< conn)
[table] -> responseLBS status200 [json] <$>
( if verb == methodOptions
then printColumns table =<< conn
else selectWhere table qq =<< conn )
_ -> return $ responseLBS status404 [] ""
respond r
where
path = pathInfo req
verb = requestMethod req