scotty 0.4.5 → 0.4.6
raw patch · 4 files changed
+42/−31 lines, 4 filesdep ~aesondep ~blaze-builderdep ~case-insensitive
Dependency ranges changed: aeson, blaze-builder, case-insensitive, conduit, data-default, http-types, mtl, resourcet, text, wai, wai-extra, warp
Files
- Web/Scotty/Route.hs +16/−2
- examples/json.hs +5/−5
- examples/urlshortener.hs +5/−1
- scotty.cabal +16/−23
Web/Scotty/Route.hs view
@@ -12,7 +12,11 @@ import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as BL+import Data.Conduit (($$), (=$))+import Data.Conduit.Binary (sourceLbs) import Data.Conduit.Lazy (lazyConsume)+import Data.Conduit.List (consume)+import Data.Either (partitionEithers) import Data.Maybe (fromMaybe) import Data.Monoid (mconcat) import qualified Data.Text.Lazy as T@@ -20,7 +24,7 @@ import Network.HTTP.Types import Network.Wai-import Network.Wai.Parse (parseRequestBody, lbsBackEnd)+import qualified Network.Wai.Parse as Parse hiding (parseRequestBody) import qualified Text.Regex as Regex @@ -131,11 +135,21 @@ path :: Request -> T.Text path = T.fromStrict . TS.cons '/' . TS.intercalate "/" . pathInfo +-- Stolen from wai-extra, modified to accept body as lazy ByteString+parseRequestBody :: BL.ByteString+ -> Parse.BackEnd y+ -> Request+ -> ResourceT IO ([Parse.Param], [Parse.File y])+parseRequestBody b s r =+ case Parse.getRequestBodyType r of+ Nothing -> return ([], [])+ Just rbt -> fmap partitionEithers $ sourceLbs b $$ Parse.conduitRequestBody s rbt =$ consume+ mkEnv :: Request -> [Param] -> ResourceT IO ActionEnv mkEnv req captures = do b <- BL.fromChunks <$> lazyConsume (requestBody req) - (formparams, fs) <- parseRequestBody lbsBackEnd req+ (formparams, fs) <- parseRequestBody b Parse.lbsBackEnd req let convert (k, v) = (strictByteStringToLazyText k, strictByteStringToLazyText v) parameters = captures ++ map convert formparams ++ queryparams
examples/json.hs view
@@ -9,7 +9,7 @@ import qualified Text.Blaze.Html5 as H import Text.Blaze.Html5 ((!)) import Text.Blaze.Html5.Attributes as A-import Text.Blaze.Renderer.Text (renderHtml)+import Text.Blaze.Html.Renderer.Text (renderHtml) import Web.Scotty @@ -29,7 +29,7 @@ get "/" $ do html $ wrapper $ do H.form ! A.id "fooform" ! method "post" ! action "#" $ do- H.text "Select a constructor: "+ H.h5 "Select a constructor: " H.input ! type_ "radio" ! A.id "fooquux" ! name "con" ! value "Quux" H.label ! for "fooquux" $ "Quux" H.input ! type_ "radio" ! A.id "foobar" ! name "con" ! value "Bar"@@ -37,12 +37,12 @@ H.input ! type_ "radio" ! A.id "foobaz" ! name "con" ! value "Baz" H.label ! for "foobaz" $ "Baz" H.br- H.text "Enter an int: "+ H.h5 "Enter an int: " H.input ! type_ "text" ! class_ "barfields" ! name "Barint" H.br- H.text "Enter a float: "+ H.h5 "Enter a float: " H.input ! type_ "text" ! class_ "bazfields" ! name "Bazfloat"- H.text "Enter a string: "+ H.h5 "Enter a string: " H.input ! type_ "text" ! class_ "bazfields" ! name "Bazstring" H.br H.input ! type_ "submit"
examples/urlshortener.hs view
@@ -12,7 +12,11 @@ import qualified Text.Blaze.Html5 as H import Text.Blaze.Html5.Attributes-import Text.Blaze.Renderer.Text (renderHtml)+-- Note:+-- Scotty does not require blaze-html or+-- wai-middleware-static, but this example does+-- cabal install blaze-html wai-middleware-static+import Text.Blaze.Html.Renderer.Text (renderHtml) -- TODO: -- Implement some kind of session and/or cookies
scotty.cabal view
@@ -1,8 +1,8 @@ Name: scotty-Version: 0.4.5+Version: 0.4.6 Synopsis: Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp-Homepage: https://github.com/xich/scotty-Bug-reports: https://github.com/xich/scotty/issues+Homepage: https://github.com/ku-fpg/scotty+Bug-reports: https://github.com/ku-fpg/scotty/issues License: BSD3 License-file: LICENSE Author: Andrew Farmer <anfarmer@ku.edu>@@ -39,13 +39,6 @@ . * Uses very fast Warp webserver by default. .- This design has been done in Haskell at least once before (to my knowledge) by- the miku framework. My issue with miku is that it uses the Hack2 interface- instead of WAI (they are analogous, but the latter seems to have more traction),- and that it is written using a custom prelude called Air (which appears to be an- attempt to turn Haskell into Ruby syntactically). I wanted something that- depends on relatively few other packages, with an API that fits on one page.- . As for the name: Sinatra + Warp = Scotty. . [WAI] <http://hackage.haskell.org/package/wai>@@ -69,24 +62,24 @@ Web.Scotty.Types Web.Scotty.Util default-language: Haskell2010- build-depends: aeson >= 0.5,+ build-depends: aeson >= 0.6.0.2, base >= 4.3.1 && < 5,- blaze-builder >= 0.3,+ blaze-builder >= 0.3.1.0, bytestring >= 0.9.1,- case-insensitive >= 0.4,- conduit >= 0.4.0.1 && < 0.6,- data-default >= 0.3,- http-types >= 0.6.8 && < 0.8,- mtl >= 2.0.1,- resourcet >= 0.3.2 && < 0.4,- text >= 0.11.1,- wai >= 1.0.0,- warp >= 1.0.0,+ case-insensitive >= 0.4.0.3,+ conduit >= 0.5.2.7,+ data-default >= 0.5.0,+ http-types >= 0.7.3.0.1,+ mtl >= 2.1.2, regex-compat >= 0.95.1,- wai-extra >= 1.2+ resourcet >= 0.4.0.2,+ text >= 0.11.2.3,+ wai >= 1.3.0.1,+ wai-extra >= 1.3.0.3,+ warp >= 1.3.4.1 GHC-options: -Wall -fno-warn-orphans source-repository head type: git- location: git://github.com/xich/scotty.git+ location: git://github.com/ku-fpg/scotty.git