From a28553dd45edf783e42816552a173caf01ebc96f Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Sun, 13 Jul 2014 10:31:47 -0700 Subject: [PATCH] Simplify app with a do block --- Main.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Main.hs b/Main.hs index 595774545..e8c77ece2 100644 --- a/Main.hs +++ b/Main.hs @@ -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