Simplify app with a do block
This commit is contained in:
@@ -44,14 +44,18 @@ main = do
|
|||||||
describe = progDesc "create a REST API to an existing Postgres database"
|
describe = progDesc "create a REST API to an existing Postgres database"
|
||||||
|
|
||||||
app :: AppConfig -> Application
|
app :: AppConfig -> Application
|
||||||
app config req respond =
|
app config req respond = do
|
||||||
case path of
|
r <-
|
||||||
[] -> respond =<< responseLBS status200 [json] <$> (printTables =<< conn)
|
case path of
|
||||||
[table] -> respond =<< (<$>) (responseLBS status200 [json])
|
[] -> responseLBS status200 [json] <$> (printTables =<< conn)
|
||||||
( if verb == methodOptions
|
[table] -> responseLBS status200 [json] <$>
|
||||||
then printColumns table =<< conn
|
( if verb == methodOptions
|
||||||
else selectWhere table qq =<< conn )
|
then printColumns table =<< conn
|
||||||
_ -> respond $ responseLBS status404 [] ""
|
else selectWhere table qq =<< conn )
|
||||||
|
_ -> return $ responseLBS status404 [] ""
|
||||||
|
|
||||||
|
respond r
|
||||||
|
|
||||||
where
|
where
|
||||||
path = pathInfo req
|
path = pathInfo req
|
||||||
verb = requestMethod req
|
verb = requestMethod req
|
||||||
|
|||||||
Reference in New Issue
Block a user