Skip to content

Instantly share code, notes, and snippets.

@deian
Created July 3, 2013 19:08
Show Gist options
  • Save deian/5921778 to your computer and use it in GitHub Desktop.
Save deian/5921778 to your computer and use it in GitHub Desktop.
key-value store hails
{-# LANGUAGE OverloadedStrings #-}
module SimpleApp2 (server) where
import Prelude hiding (lookup)
import Data.String
import Control.Monad
import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy.Char8 as L8
import LIO
import Hails.Web
import qualified Hails.Web.Frank as Frank
import Hails.HttpServer
import Hails.Database
import SimplePolicyModule
server :: Application
server = mkRouter $ do
Frank.post "/store" $ do
doc <- include ["key","val"] `liftM` hsonRequest
if length doc /= 2
then respond badRequest
else do liftLIO $ withStorePolicyModule $ insert "store" doc
respond $ redirectTo $ "/store/" ++ ("key" `at` doc)
where hsonRequest :: Controller Document
hsonRequest = request >>= labeledRequestToHson >>= (liftLIO . unlabel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment