Copyright | (c) 2015 Futurice |
---|---|
License | MIT (see the file LICENSE) |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Network.Waitra
is a very simple router.
It's useful for writing simple API web-services,
when you don't want to use the whole Yesod stack.
- type Path = String
- data Route = Route Method (RE Char Application)
- simpleRoute :: Method -> Path -> Application -> Route
- simpleGet :: Path -> Application -> Route
- simplePost :: Path -> Application -> Route
- simplePut :: Path -> Application -> Route
- simpleDelete :: Path -> Application -> Route
- routeGet :: RE Char Application -> Route
- routePost :: RE Char Application -> Route
- routePut :: RE Char Application -> Route
- routeDelete :: RE Char Application -> Route
- jsonApp :: (FromJSON a, ToJSON b) => (a -> IO (Status, ResponseHeaders, b)) -> Application
- jsonApp' :: ToJSON b => IO (Status, ResponseHeaders, b) -> Application
- routeMiddleware :: Route -> Middleware
- waitraMiddleware :: [Route] -> Middleware
Types
We use strings, as - unluckily - Applicative
doesn't work with Text
directly.
Static paths routes
simpleRoute :: Method -> Path -> Application -> Route Source
simpleGet :: Path -> Application -> Route Source
simplePost :: Path -> Application -> Route Source
simplePut :: Path -> Application -> Route Source
simpleDelete :: Path -> Application -> Route Source
Regex paths routes
routeDelete :: RE Char Application -> Route Source
JSON helper
jsonApp :: (FromJSON a, ToJSON b) => (a -> IO (Status, ResponseHeaders, b)) -> Application Source
jsonApp' :: ToJSON b => IO (Status, ResponseHeaders, b) -> Application Source
Compilation
routeMiddleware :: Route -> Middleware Source
waitraMiddleware :: [Route] -> Middleware Source
Turn the list of routes into Middleware