firefly 0.1.0.0 → 0.1.0.1
raw patch · 5 files changed
+71/−27 lines, 5 filesdep ~aesondep ~blaze-htmldep ~bytestringPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependency ranges changed: aeson, blaze-html, bytestring, case-insensitive, containers, cookie, http-types, mtl, regex-pcre, text, transformers, wai, warp
API changes (from Hackage documentation)
+ Web.Firefly.Request: getHeader :: ReqReader m => Text -> m (Maybe Text)
+ Web.Firefly.Request: getHeaderMulti :: ReqReader m => Text -> m [Text]
Files
- README.md +45/−11
- firefly.cabal +15/−14
- src/Web/Firefly/Handler.hs +0/−1
- src/Web/Firefly/Request.hs +10/−0
- src/Web/Firefly/Types.hs +1/−1
README.md view
@@ -1,4 +1,5 @@ # Firefly+[](https://travis-ci.org/ChrisPenner/Firefly) - [Example App](./firefly-example/app/Main.hs) - [Hackage Docs](http://hackage.haskell.org/package/firefly-0.1.0.0/docs/Web-Firefly.html)@@ -9,7 +10,7 @@ It's great for people learning Haskell, fiddling with Monads, or who just need a really simple server for something. -Here's the minimal app:+Here's a simple app: ```haskell {-# language OverloadedStrings #-}@@ -21,7 +22,14 @@ app :: App () app = do- route "/hello" (return "hello" :: Handler T.Text)+ route "/hello" helloHandler++-- | Get the 'name' query param from the url, if it doesn't exist use 'Stranger'+helloHandler :: Handler T.Text+helloHandler = do+ name <- fromMaybe "Stranger" <$> getQuery "name"+ return $ "Hello " `T.append` name+ ``` Just that easy!@@ -51,15 +59,6 @@ Let's write some more interesting handlers: -```haskell-hello :: App T.Text-hello = do- -- | Get the 'name' query param from the url, if it doesn't exist use 'Stranger'- name <- getQuery "name"- -- If we just return some Text the response will be status 200 with a Content-Type of "text/plain"- return $ "Hello " <> fromMaybe "Stranger" name-```- Here's an example of responding with JSON: ```haskell@@ -85,6 +84,7 @@ return $ case uname of -- The Json constructor signals to serialize the value and respond as "application/json" Just "steve" -> toResponse $ Json steve + -- We can use a tuple to pass a status alongside the response body Just name -> toResponse ("Couldn't find user: " `mappend` name, notFound404) Nothing -> toResponse ("Please provide a 'username' parameter" :: T.Text, badRequest400) ```@@ -102,3 +102,37 @@ - You'll have thousands of users - You want the most performant server possible - You want to have lots of helper libs available++## Troubleshooting++### pcre.h not found++Seeing something like this?+```+...stack/regex-pcre-0.94.4/Wrap.hsc:148:10: fatal error: 'pcre.h' file not found+ #include <pcre.h>+ ^~~~~~~~+ 1 error generated.+```++Firefly uses regex; and requires certain c-libs to be installed. The easiest way to fix this is to install Nix:++[Get Nix](https://nixos.org/nix/)++*or* run:++`curl https://nixos.org/nix/install | sh`++Then add the following to your project's `stack.yaml`:++```+nix:+ enable: true+ packages:+ - libcxx+ - icu+ - gcc+ - ncurses+ - pcre+ - zlib+```
firefly.cabal view
@@ -1,5 +1,5 @@ name: firefly-version: 0.1.0.0+version: 0.1.0.1 synopsis: A simple HTTP server framework -- description: homepage: https://github.com/ChrisPenner/firefly#readme@@ -12,6 +12,7 @@ build-type: Simple extra-source-files: README.md cabal-version: >=1.10+tested-with: GHC==8.2.1, GHC==8.0.2 library hs-source-dirs: src@@ -24,19 +25,19 @@ Web.Firefly.Types build-depends: base >= 4.7 && < 5- , wai- , warp- , cookie- , mtl- , http-types- , bytestring- , text- , containers- , case-insensitive- , transformers- , regex-pcre- , blaze-html- , aeson+ , wai >= 3.2+ , warp >= 3.2+ , cookie >= 0.4.2+ , mtl >= 2.2+ , http-types >= 0.9+ , bytestring >= 0.10+ , text >= 1.2+ , containers >= 0.5+ , case-insensitive >= 1.2+ , transformers >= 0.5+ , regex-pcre >= 0.94+ , blaze-html >= 0.9+ , aeson >= 1.1 default-language: Haskell2010 source-repository head
src/Web/Firefly/Handler.hs view
@@ -35,7 +35,6 @@ route :: (ToResponse r) => Pattern -> Handler r -> App () route routePath handler = do path <- getPath- liftIO . print $ "checking" `T.append` routePath when (routePath `matches` path) (handler >>= respond . toResponse) -- | Determine whether a route matches a pattern
src/Web/Firefly/Request.hs view
@@ -11,6 +11,8 @@ , getQueriesMulti , getQuery , getQueryMulti+ , getHeader+ , getHeaderMulti , getHeaders , getBody , getCookies@@ -55,6 +57,14 @@ -- | Gets full body of the request getBody :: ReqReader m => m T.Text getBody = asks requestBody++-- | Gets the headers of the request+getHeader :: ReqReader m => T.Text -> m (Maybe T.Text)+getHeader key = listToMaybe <$> getHeaderMulti key++-- | Gets the headers of the request+getHeaderMulti :: ReqReader m => T.Text -> m [T.Text]+getHeaderMulti key = fromMaybe [] . M.lookup (CI.mk key) <$> getHeaders -- | Gets the headers of the request getHeaders :: ReqReader m => m HeaderMap
src/Web/Firefly/Types.hs view
@@ -7,7 +7,7 @@ import qualified Data.Map as M import qualified Data.CaseInsensitive as CI --- | The main application definiton monad, sequence your+-- | The main application definition monad, sequence your -- route handlers and/or middleware in this monad type App a = ReaderT ReqContext (ExceptT W.Response IO) a