Better way to send JSON
This commit is contained in:
parent
ab9ef4e277
commit
257e94f474
@ -8,7 +8,7 @@ import Views
|
||||
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Text.Printf (printf)
|
||||
import Data.Aeson
|
||||
import Data.Aeson hiding (json)
|
||||
import Data.Monoid
|
||||
import Data.Text (pack, unpack)
|
||||
import Data.Text.Lazy.Encoding (decodeUtf8)
|
||||
@ -40,7 +40,7 @@ app url' table = do
|
||||
logStr (printf "Resolved %s -> %s" name url)
|
||||
redirect (pack url)
|
||||
|
||||
post root $ do
|
||||
post "/" $ do
|
||||
url <- fmap unpack <$> param "url"
|
||||
case url of
|
||||
Nothing -> html (render $ message "bad request")
|
||||
@ -57,7 +57,6 @@ app url' table = do
|
||||
Just url -> do
|
||||
name <- liftIO (insert table url)
|
||||
logStr (printf "Registered %s -> %s " url name)
|
||||
let json = object [ "link" .= pack (url' <> name)
|
||||
, "name" .= name
|
||||
, "original" .= url ]
|
||||
text (toStrict $ decodeUtf8 $ encode json)
|
||||
json $ object [ "link" .= pack (url' <> name)
|
||||
, "name" .= name
|
||||
, "original" .= url ]
|
||||
|
Loading…
Reference in New Issue
Block a user