growler-0.6.0: A revised version of the scotty library that attempts to be simpler and more performant.

Safe HaskellNone
LanguageHaskell2010

Web.Growler.Router

Synopsis

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.

handlerHook :: Monad m => (HandlerT m () -> HandlerT m ()) -> GrowlerT m () Source

notFound :: Monad m => HandlerT m () Source

A blank 404 Not Found handler for convenience.

internalServerError :: Monad m => HandlerT m () Source

A blank 500 Internal Server Error handler for convenience.