Safe Haskell | None |
---|---|
Language | Haskell2010 |
>>>
:set -XDataKinds -XPolyKinds -XOverloadedStrings
>>>
data Proxy s = Proxy
>>>
import Text.Read(readMaybe)
>>>
import qualified Data.Text as T
- create path
>>>
data Result = A | B T.Text | C | D Int | E T.Text deriving Show
>>>
let key = Proxy :: Proxy "key"
>>>
let a = root $ exact "foo" $ action Nothing (\_ -> Just A)
>>>
let b = root $ exact "bar" $ fetch key Just $ action Nothing (\d -> Just . B $ D.get key d)
>>>
let c = root $ exact "bar" $ any $ action (Just "GET") (\_ -> Just C)
>>>
let d = root $ exact "bar" $ fetch key (\t -> readMaybe (T.unpack t) :: Maybe Int) $ action Nothing (\d -> Just . D $ D.get key d)
>>>
let e = root $ exact "foo" $ fetch key Just $ exact "qux" $ action (Just "POST") (\d -> Just . E $ D.get key d)
>>>
a
* /foo>>>
b
* /bar/:key>>>
c
GET /bar/**>>>
d
* /bar/:key>>>
e
POST /foo/:key/qux
- create router
>>>
let r = e +| d +| a +| b +| c +| empty
- execute router
>>>
let run = execute r
>>>
run "GET" ["foo"]
Just A>>>
run "GET" ["foo", "bar"]
Nothing>>>
run "GET" ["bar", "12"]
Just (D 12)>>>
run "GET" ["bar", "baz"]
Just (B "baz")>>>
run "GET" ["bar", "baz", "qux"]
Just C>>>
run "POST" ["bar", "baz", "qux"]
Nothing>>>
run "POST" ["foo", "bar", "baz"]
Nothing>>>
run "POST" ["foo", "bar", "qux"]
Just (E "bar")
- type Method = ByteString
- data Path d m a
- showPath :: Path d m a -> String
- getMethod :: Path d m a -> Maybe Method
- root :: Path '[] m a -> Path '[] m a
- exact :: Text -> Path d m a -> Path d m a
- action :: Maybe Method -> (Dict d -> m a) -> Path d m a
- type Raw m d d' = Store d -> [Text] -> m (Store d', [Text])
- raw :: String -> Raw m d d' -> Path d' m a -> Path d m a
- fetch :: (MonadPlus m, KnownSymbol k, k </ d) => proxy k -> (Text -> Maybe v) -> Path ((k := v) ': d) m a -> Path d m a
- any :: Monad m => Path d m a -> Path d m a
- rest :: (KnownSymbol k, Monad m, k </ d) => proxy k -> Path ((k := [Text]) ': d) m a -> Path d m a
- data Router d m a
- empty :: MonadPlus m => Router '[] m a
- insert :: MonadPlus m => Path '[] m a -> Router '[] m a -> Router '[] m a
- (+|) :: MonadPlus m => Path '[] m a -> Router '[] m a -> Router '[] m a
- execute :: MonadPlus m => Router '[] m a -> Method -> [Text] -> m a
- module Data.Apiary.Routing.Dict
Documentation
type Method = ByteString Source #
Path
children
action
:: Maybe Method | if Nothing, any method allowed |
-> (Dict d -> m a) | action when route matching |
-> Path d m a |
action
get parameter
get one directory as parameter.
raw get parameter function
if you want matching exact path, use exact
for performance
:: (KnownSymbol k, Monad m, k </ d) | |
=> proxy k | dictionary key |
-> Path ((k := [Text]) ': d) m a | |
-> Path d m a |
take any pathes as [Text]
Router
insert :: MonadPlus m => Path '[] m a -> Router '[] m a -> Router '[] m a infixr 9 Source #
insert path to router
(+|) :: MonadPlus m => Path '[] m a -> Router '[] m a -> Router '[] m a infixr 9 Source #
infix version of insert
execute
reexport
module Data.Apiary.Routing.Dict