bird 0.0.11 → 0.0.12
raw patch · 5 files changed
+47/−19 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bird.BirdResponder: body :: (MonadState Reply m) => String -> m ()
- Bird.BirdResponder: param :: (MonadReader Request m) => String -> m (Maybe String)
- Bird.BirdResponder: runBirdResponder :: (Default a, Monad m) => r -> (r -> StateT a (ReaderT r m) a1) -> m a
- Bird.BirdResponder: status :: (MonadState Reply m) => Int -> m ()
- Bird.Reply: replyMime :: Reply -> String
- Bird.Reply: Reply :: Int -> Map String String -> String -> String -> Reply
+ Bird.Reply: Reply :: Int -> Map String String -> String -> Reply
Files
- bird.cabal +1/−1
- readme.markdown +30/−5
- src/Bird/BirdResponder.hs +8/−7
- src/Bird/Reply.hs +4/−5
- src/Bird/Translator/Hack.hs +4/−1
bird.cabal view
@@ -1,5 +1,5 @@ Name: bird-Version: 0.0.11+Version: 0.0.12 Build-type: Simple Synopsis: A simple, sinatra-inspired web framework. Description: Bird is a hack-compatible framework for simple websites.
readme.markdown view
@@ -58,15 +58,32 @@ name <- param "name" body $ "Greetings, " ++ (maybe "Jedi!" id name) -now:+now recompile your app and start it flying: - λ curl http://localhost:3000/force/Han/Chewie+ λ bird nest + λ bird fly & + + λ curl -i http://localhost:3000/force/Han/Chewie+ + HTTP/1.1 200 OK+ Connection: close+ Content-Type: text/html+ Date: Sat, 31 Jul 2010 14:07:17 GMT+ Server: Happstack/0.5.0.2+ May the force be with you Han, Chewie! - λ curl http://localhost:3000/droids- Nothing to see here. Move along.+ λ curl -i http://localhost:3000/droids+ + HTTP/1.1 404 Not Found+ Connection: close+ Content-Type: text/html+ Date: Sat, 31 Jul 2010 14:08:35 GMT+ Server: Happstack/0.5.0.2 + These aren't the droids you're looking for. Move along. + ## API You have four functions to implement: get, post, put, and delete. They each accept a Bird Request. @@ -80,8 +97,16 @@ body :: String -> BirdRouter () -- takes a string and sets the Http Response body to whatever the string contained. - status :: Integer -> BirdRouter ()+ status :: Integer -> BirdResponder () -- takes a number, and sets the HTTP Reponse header "Status" to that number.++ mime :: String -> BirdResponder ()+ -- sets the mime type to whatever you provide+ -- ex: get [] = body "Hello World" >> mime "text/plain"++ header :: String -> String -> BirdResponder ()+ -- creates/updates a header+ -- ex: get [] = body "Hello World" >> header "X-Powered-By" "BIRD!" ## Notes
src/Bird/BirdResponder.hs view
@@ -1,10 +1,4 @@-module Bird.BirdResponder(- BirdResponder-, runBirdResponder-, body-, status-, param-) where+module Bird.BirdResponder where import Control.Monad.State import Control.Monad.Reader@@ -12,6 +6,7 @@ import Data.Maybe import Bird.Reply import Bird.Request+import qualified Data.Map as Hash type BirdResponder = StateT Reply (ReaderT Request IO) @@ -29,3 +24,9 @@ param paramName = do request <- ask return $ maybe Nothing id (lookup paramName $ params request)++mime m = header "Content-Type" m++header k v = do+ reply <- get+ put $ reply { replyHeaders = Hash.insert k v $ replyHeaders reply }
src/Bird/Reply.hs view
@@ -5,11 +5,10 @@ data Reply = Reply {- replyStatus :: Int,- replyHeaders :: Hash.Map String String,- replyBody :: String,- replyMime :: String+ replyStatus :: Int+ , replyHeaders :: Hash.Map String String+ , replyBody :: String } deriving (Show) instance Default Reply where- def = Reply { replyMime = "text/html", replyBody = "", replyStatus = 200, replyHeaders = Hash.empty }+ def = Reply { replyBody = "", replyStatus = 200, replyHeaders = Hash.insert "Content-Type" "text/html" Hash.empty }
src/Bird/Translator/Hack.hs view
@@ -15,9 +15,11 @@ fromBirdReply r = Hack.Response { Hack.status = replyStatus r,- Hack.headers = [("Content-Type", replyMime r)] ++ (Hash.toList $ replyHeaders r),+ Hack.headers = (Hash.toList $ Hash.insertWith insertUnlessPresent "Content-Type" "text/html" $ replyHeaders r), Hack.body = pack $ replyBody r }+ where+ insertUnlessPresent _ oldValue = oldValue instance BirdRequestTranslator Hack.Env where toBirdRequest e = @@ -26,6 +28,7 @@ , path = split '/' $ Hack.pathInfo e , params = parseQueryString $ Hack.queryString e }+ hackRequestMethodToBirdRequestMethod rm = case rm of