Safe Haskell | None |
---|---|
Language | Haskell2010 |
- get :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- post :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- put :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- delete :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- patch :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- addRoute :: MonadIO m => StdMethod -> RoutePattern -> HandlerT m () -> GrowlerT m ()
- matchAny :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m ()
- capture :: String -> RoutePattern
- regex :: String -> RoutePattern
- function :: (Request -> Text) -> (Request -> MatchResult) -> RoutePattern
- mount :: Monad m => RoutePattern -> GrowlerT m () -> GrowlerT m ()
- literal :: String -> RoutePattern
- route :: Request -> StdMethod -> RoutePattern -> Maybe (Text, [Param])
- handlerHook :: Monad m => (HandlerT m () -> HandlerT m ()) -> GrowlerT m ()
- newtype RoutePattern = RoutePattern {}
- notFound :: Monad m => HandlerT m ()
- internalServerError :: Monad m => HandlerT m ()
Documentation
addRoute :: MonadIO m => StdMethod -> RoutePattern -> HandlerT m () -> GrowlerT m () Source
Define a route with a StdMethod
, Text
value representing the path spec,
and a body (Action
) which modifies the response.
addroute GET "/" $ text "beam me up!"
The path spec can include values starting with a colon, which are interpreted
as captures. These are named wildcards that can be looked up with param
.
addroute GET "/foo/:bar" $ do v <- param "bar" text v
>>>
curl http://localhost:3000/foo/something
something
matchAny :: MonadIO m => RoutePattern -> HandlerT m () -> GrowlerT m () Source
Add a route that matches regardless of the HTTP verb.
capture :: String -> RoutePattern Source
Standard Sinatra-style route. Named captures are prepended with colons. This is the default route type generated by OverloadedString routes. i.e.
get (capture "/foo/:bar") $ ...
and
{-# LANGUAGE OverloadedStrings #-} ... get "/foo/:bar" $ ...
are equivalent.
regex :: String -> RoutePattern Source
Match requests using a regular expression. Named captures are not yet supported.
get (regex "^/f(.*)r$") $ do path <- param "0" cap <- param "1" text $ mconcat ["Path: ", path, "\nCapture: ", cap]
>>>
curl http://localhost:3000/foo/bar
Path: /foo/bar Capture: oo/ba
function :: (Request -> Text) -> (Request -> MatchResult) -> RoutePattern Source
Build a route based on a function which can match using the entire Request
object.
Nothing
indicates the route does not match. A Just
value indicates
a successful match, optionally returning a list of key-value pairs accessible
by param
.
get (function $ \req -> Just [("version", T.pack $ show $ httpVersion req)]) $ do v <- param "version" text v
>>>
curl http://localhost:3000/
HTTP/1.1
literal :: String -> RoutePattern Source
Build a route that requires the requested path match exactly, without captures.
newtype RoutePattern Source
internalServerError :: Monad m => HandlerT m () Source
A blank 500 Internal Server Error handler for convenience.