Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bird 0.0.18 - processing x-www-form-urlencoded parameters.

  • Loading branch information...
commit 6437a34699b9630dca403bd48a78947b9489059e 1 parent cf57999
@moonmaster9000 authored
View
67 CHANGELOG
@@ -1,67 +0,0 @@
-v0.0.17
-You are now free to organize your get/post/put/delete functions freely:
-
- -- blog posts admin actions
- get ["admin", "posts"] = do ....
- post ["admin", "posts"] = do ....
- put ["admin", "posts", id] = do ....
- delete ["admin", "posts", id] = do ....
-
- -- blog frontend
- get ["posts"] = do ....
- get ["posts", year, month, day] = do ....
- get ["posts", year, month, day, id] = do ....
- post ["posts", year, month, day, id, "comments"] = do ....
-
-In normal haskell, you'd be forced to group ALL of your get functions together, all of your post functions together, etc. etc. But bird lets you fly freely.
-
-
-v0.0.16
-now includes logging! To add to the log in your get/post/put/delete methods, simply call the "log" action with a string log message.
-if you want to plug in your own custom logger, set it in your MyApp/MyApp/Config.hs file:
-
- config =
- def {
- birdLogger = myCustomLogger
- }
-
-your custom logger method signature must be: Request -> (Request -> BirdResponder ()) -> IO Reply
-
-v0.0.14
-better "bird" command, thanks to @jasondew. "bird hatch MyApp" for a new app; "bird help" or "bird --help" for more info.
-
-v0.0.13
-'bird nest' now cleans up after itself.
-
-v0.0.12
-`mime` and `header` methods available for your get/post/put/delete function bodies.
-
-e.g.:
-
- get [] = do
- body "Hello, World!"
- mime "text/plain"
- header "X-Powered-By" "bird"
-
-v0.0.11
-Your application code just got simpler. bird MyApp and check it out. 'get [] = body "Hello World"' constitutes a complete and valid bird app.
-
-v0.0.4
-Using "Rallod" for forward function application.
-
-v0.0.3
-Hack.Handler.Happstack is now the default hack server handler.
-Also, "bird build" has been replaced with "bird nest" and "bird run" with "bird fly"
-
-v0.0.2
-added support for query string. it's accessible in the request record from "params".
-it's a Data.Map.
-e.g.:
- > module Blog where
- > import Bird
-
- > get, post, put, delete :: Request -> IO Reply
- > get r = ok $ "query string = " ++ (show $ params r)
- > post _ = return notFound_
- > put _ = return notFound_
- > delete _ = return notFound_
View
94 HISTORY.lhs
@@ -0,0 +1,94 @@
+# v0.0.18
+
+Basic param processing for POST/PUT's that have the content type "application/x-www-form-urlencoded". e.g.:
+
+ λ bird hatch StarWars && cd StarWars
+ λ vim StarWars.bird.hs
+
+ > post ["jedi"] = do
+ > name <- param "name"
+ > teacher <- param "teacher"
+ > case teacher of
+ > Just "Yoda" -> body "The force is strong with this one!" >> status 201
+ > _ -> body "Sorry. The force is not with this one." >> status 400
+
+ λ bird nest
+ λ bird fly &
+ λ curl -i -X POST http://localhost:3000/jedi -d name=Luke -d teacher=Yoda
+
+ HTTP/1.1 201 Created
+ Connection: close
+ Content-Type: text/html
+ Date: Sat, 21 Aug 2010 21:38:11 GMT
+ Server: Happstack/0.5.0.2
+
+ The force is strong with this one!
+
+
+# v0.0.17
+You are now free to organize your get/post/put/delete functions freely:
+
+ > -- blog posts admin actions
+ > get ["admin", "posts"] = do ....
+ > post ["admin", "posts"] = do ....
+ > put ["admin", "posts", id] = do ....
+ > delete ["admin", "posts", id] = do ....
+
+ > -- blog frontend
+ > get ["posts"] = do ....
+ > get ["posts", year, month, day] = do ....
+ > get ["posts", year, month, day, id] = do ....
+ > post ["posts", year, month, day, id, "comments"] = do ....
+
+In normal haskell, you'd be forced to group ALL of your get functions together, all of your post functions together, etc. etc. But bird lets you fly freely.
+
+
+#v0.0.16
+now includes logging! To add to the log in your get/post/put/delete methods, simply call the "log" action with a string log message.
+if you want to plug in your own custom logger, set it in your MyApp/MyApp/Config.hs file:
+
+ > config =
+ > def {
+ > birdLogger = myCustomLogger
+ > }
+
+your custom logger method signature must be: Request -> (Request -> BirdResponder ()) -> IO Reply
+
+#v0.0.14
+better "bird" command, thanks to @jasondew. "bird hatch MyApp" for a new app; "bird help" or "bird --help" for more info.
+
+#v0.0.13
+'bird nest' now cleans up after itself.
+
+#v0.0.12
+`mime` and `header` methods available for your get/post/put/delete function bodies.
+
+e.g.:
+
+ > get [] = do
+ > body "Hello, World!"
+ > mime "text/plain"
+ > header "X-Powered-By" "bird"
+
+#v0.0.11
+Your application code just got simpler. bird MyApp and check it out. 'get [] = body "Hello World"' constitutes a complete and valid bird app.
+
+#v0.0.4
+Using "Rallod" for forward function application.
+
+#v0.0.3
+Hack.Handler.Happstack is now the default hack server handler.
+Also, "bird build" has been replaced with "bird nest" and "bird run" with "bird fly"
+
+#v0.0.2
+added support for query string. it's accessible in the request record from "params".
+it's a Data.Map.
+e.g.:
+ > module Blog where
+ > import Bird
+
+ > get, post, put, delete :: Request -> IO Reply
+ > get r = ok $ "query string = " ++ (show $ params r)
+ > post _ = return notFound_
+ > put _ = return notFound_
+ > delete _ = return notFound_
View
20 README.markdown
@@ -48,6 +48,14 @@ Note: make sure $HOME/.cabal/bin is in your PATH.
body "These aren't the droids you're looking for. Move along."
status 404
+ post ["jedi"] = do
+ name <- param "name"
+ teacher <- param "teacher"
+ case teacher of
+ Just "Yoda" -> body "The force is strong with this one!" >> status 201
+ _ -> body "Sorry. The force is not with this one." >> status 400
+
+
get ("force":xs) = do
body $ "May the force be with you " ++ (join ", " xs) ++ "!"
@@ -71,6 +79,18 @@ Now recompile your app and start it flying:
May the force be with you Han, Chewie!
+
+ λ curl -i -X POST http://localhost:3000/jedi -d name=Luke -d teacher=Yoda
+
+ HTTP/1.1 201 Created
+ Connection: close
+ Content-Type: text/html
+ Date: Sat, 21 Aug 2010 21:38:11 GMT
+ Server: Happstack/0.5.0.2
+
+ The force is strong with this one!
+
+
λ curl -i http://localhost:3000/droids
HTTP/1.1 404 Not Found
View
4 bird.cabal
@@ -1,5 +1,5 @@
Name: bird
-Version: 0.0.17
+Version: 0.0.18
Build-type: Simple
Synopsis: A simple, sinatra-inspired web framework.
Description: Bird is a hack-compatible framework for simple websites.
@@ -19,5 +19,5 @@ Executable bird
library
build-depends: haskell98, MissingH >= 1.1.0.3, mtl >= 1.1.0.2, process, containers, parsec >= 2.1.0.1, bytestring, base >= 4.0 && < 5, hack >= 2009.10.30, hack-handler-happstack, data-default >= 0.2, rallod
- exposed-modules: Bird, Bird.Logger, Bird.Config, Bird.Request, Bird.Reply, Bird.Request.QueryStringParser, Bird.BirdResponder, Bird.Translator, Bird.Translator.Hack
+ exposed-modules: Bird, Bird.Logger, Bird.Config, Bird.Request, Bird.Reply, Bird.Request.QueryStringParser, Bird.Request.UrlencodedFormParser, Bird.BirdResponder, Bird.Translator, Bird.Translator.Hack
hs-source-dirs: src/
View
7 src/Bird/Request/UrlencodedFormParser.hs
@@ -0,0 +1,7 @@
+module Bird.Request.UrlencodedFormParser(
+ parseUrlencodedForm
+) where
+
+import Bird.Request.QueryStringParser
+
+parseUrlencodedForm = parseQueryString
View
16 src/Bird/Translator/Hack.hs
@@ -9,7 +9,8 @@ import Bird.Translator
import Bird.Request
import Bird.Reply
import Bird.Request.QueryStringParser
-import Data.ByteString.Lazy.Char8 (pack)
+import Bird.Request.UrlencodedFormParser
+import Data.ByteString.Lazy.Char8 (pack, unpack)
instance BirdReplyTranslator Hack.Response where
fromBirdReply r =
@@ -26,14 +27,21 @@ instance BirdRequestTranslator Hack.Env where
Request {
verb = hackRequestMethodToBirdRequestMethod $ Hack.requestMethod e
, path = split '/' $ Hack.pathInfo e
- , params = parseQueryString $ Hack.queryString e
- , rawRequestUri = (Hack.pathInfo e) ++ maybeQueryString e
+ , params = parsedParams
+ , rawRequestUri = (Hack.pathInfo e) ++ maybeQueryString
}
where
- maybeQueryString e =
+ maybeQueryString =
if Hack.queryString e /= ""
then "?" ++ Hack.queryString e
else ""
+ parsedQueryString = parseQueryString (Hack.queryString e)
+ parsedUrlencodedForm =
+ if (Hack.requestMethod e == Hack.POST || Hack.requestMethod e == Hack.PUT) &&
+ lookup "Content-Type" (Hack.http e) == Just "application/x-www-form-urlencoded"
+ then parseQueryString (unpack $ Hack.hackInput e)
+ else []
+ parsedParams = parsedQueryString ++ parsedUrlencodedForm
hackRequestMethodToBirdRequestMethod rm =
Please sign in to comment.
Something went wrong with that request. Please try again.