Respond with JSON mime type

Fixes #6
This commit is contained in:
Joe Nelson
2014-07-06 18:43:08 -07:00
parent e8e8d96e97
commit 3f2e20a9a7
+5 -3
View File
@@ -9,6 +9,7 @@ import Database.PostgreSQL.Simple
import Network.Wai
import Network.Wai.Handler.Warp hiding (Connection)
import Network.HTTP.Types.Status
import Network.HTTP.Types.Header
import Network.HTTP.Types.Method
import Data.Aeson (encode)
@@ -43,10 +44,10 @@ exposeDb conf = do
app :: Application
app req respond =
case path of
[] -> respond =<< responseLBS status200 [] <$> (printTables =<< conn)
[] -> respond =<< responseLBS status200 [json] <$> (printTables =<< conn)
[table] -> if verb == methodOptions
then respond =<< responseLBS status200 [] <$> (printColumns table =<< conn)
else respond =<< responseLBS status200 [] <$> encode <$> (selectAll table =<< conn)
then respond =<< responseLBS status200 [json] <$> (printColumns table =<< conn)
else respond =<< responseLBS status200 [json] <$> encode <$> (selectAll table =<< conn)
_ -> respond $ responseLBS status404 [] ""
where
path = pathInfo req
@@ -54,3 +55,4 @@ app req respond =
conn = connect defaultConnectInfo {
connectDatabase = "dbapi_test"
}
json = (hContentType, "application/json")