| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Nero
Description
This module re-exports the essential functions for quickly writing Nero
applications. Use the original modules for more specialized functions.
- data Request
- method :: Request -> ByteString
- _GET :: Prism' Request Request
- _POST :: Prism' Request Request
- path :: HasPath a => Lens' a Path
- query :: HasQuery a => Lens' a Query
- form :: Formed a => Traversal' a Form
- params :: Traversal' Request MultiMap
- param :: Param a => Text -> Traversal' a Text
- data Response
- ok :: Text -> Response
- movedPermanently :: Url -> Response
- match :: Getter Text Match
- prefixed :: Text -> Prism' Match Match
- suffixed :: Text -> Prism' Match Match
- exact :: Text -> Prism' Text ()
- sep :: Text -> Prism' Match Match
- class Target a where
- dummyRequest :: Request
- dummyRequestForm :: Request
- dummyUrl :: Url
- module Nero.Prelude
Request
An HTTP Request.
method :: Request -> ByteString Source
Show Request method.
form :: Formed a => Traversal' a Form Source
params :: Traversal' Request MultiMap Source
This Traversal lets you traverse every HTTP parameter regardless of
whether it's present in the query string or in the form encoded body
of a POST Request. In the rare case where there are HTTP parameters in
both, every parameter is still being traversed starting from the /query
string/.
You might want to use param for traversing a specific parameter.
>>>let request = dummyRequestForm & query . at "name" ?~ ["hello", "out"] & form . at "name" ?~ ["there"]>>>foldOf params request ^? ix "name"Just ["hello","out","there"]
Response
An HTTP response.
Creates an 200 OK response from the given text. It automatically encodes the text to 'utf-8'. The Mime type is text/plain.
movedPermanently :: Url -> Response Source
Matching
prefixed :: Text -> Prism' Match Match Source
This Prism' strips/prepends a prefix to the first element of a Match.
>>>pure "/hello/there" ^? prefixed "/hello/" . _headJust "there"
>>>prefixed "/hello/" # pure "there" & view _head"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>pure "hello" ^? prefixed "hello" . _headJust ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>prefixed "hello" # pure mempty & view _head"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (prefixed "hello") (review (prefixed "hello") mempty) <&> is _EmptyJust True
suffixed :: Text -> Prism' Match Match Source
This Prism' strips/appends a suffix to the first value of a Match.
>>>pure "/hello/there" ^? suffixed "there" . _headJust "/hello/"
>>>suffixed "there" # pure "/hello/" & view _head"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>pure "hello" ^? suffixed "hello" . _headJust ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>suffixed "hello" # pure mempty & view _head"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (suffixed "hello") (review (suffixed "hello") mempty) <&> is _EmptyJust True
sep :: Text -> Prism' Match Match Source
This Prism' splits/joins at the first occurrence of a boundary
for the first value of a Match.
>>>pure "hello/out/there" ^? sep "/" <&> toListOf foldedJust ["out/there","hello"]
>>>sep "/" # (pure "out/there" <> pure "hello") & view _head"hello/out/there"
Notice what happens when there is no source before or after a boundary:
>>>pure "hello/" ^? sep "/"Just ["","hello"]>>>(pure "hello/" <> pure "there") ^? sep "/"Just ["","hello","there"]
>>>pure "/hello" ^? sep "/"Just ["hello",""]>>>(pure "/hello" <> pure "there") ^? sep "/"Just ["hello","","there"]
When the source is identical to the boundary: >>> pure "hello" ^? sep "hello" Just []
Results handling
Testing
dummyRequest :: Request Source
An empty GET request useful for testing.
dummyRequestForm :: Request Source
An empty POST request with an empty form encoded body useful for testing.
Re-exports
Control.Applicative re-exports <$>, <*>, pure
Data.Foldable re-exports fold
Data.Monoid re-exports Monoid, <>, mappend, mempty
module Nero.Prelude