Created
July 3, 2013 19:08
-
-
Save deian/5921778 to your computer and use it in GitHub Desktop.
key-value store hails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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