| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Nero.Application
Contents
- type Application = Request -> IO Response
- class Server a where
- application :: a -> Application
- slashRedirect :: (Target a, HasUrl r, HasPath r) => Prism' Match Match -> (a -> Response) -> r -> Maybe Response
Server
type Application = Request -> IO Response Source
Ultimately any valid Nero server application must be transformed
. This type class facilitates the
creation of web server handling Request -> IO ResponseNero applications.
Methods
application :: a -> Application Source
Trailing slash redirection
Arguments
| :: (Target a, HasUrl r, HasPath r) | |
| => Prism' Match Match | |
| -> (a -> Response) | What to respond upon matching. |
| -> r | |
| -> Maybe Response |
Redirect with slash appended URL if only a trailing slash is needed for successful matching, otherwise it responds normally.
>>>let mkRequest p = dummyRequest & host .~ "example.com" & path .~ p>>>let respond name = ok $ "<h1>Hello " <> name <> "</h1>">>>let app = slashRedirect (prefixed "/hello/" . suffixed "/") respond :: Request -> Maybe Response
>>>app (mkRequest "/hello/there") <&> statusJust "301 Moved Permanently">>>app (mkRequest "/hello/there") >>= preview location <&> renderJust "http://example.com/hello/there/"
>>>app (mkRequest "/hello/there/") <&> statusJust "200 OK">>>app (mkRequest "/hello/there/") <&> bodyJust "<h1>Hello there</h1>"
>>>app $ mkRequest "/bye/"Nothing