Copyright | (C) 2015 Richard Wallace |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Richard Wallace <rwallace@thewallacepack.net> |
Stability | provisional |
Safe Haskell | None |
Language | Haskell98 |
- root :: Path `[]`
- (</>) :: Path as -> Path bs -> Path (Append as bs)
- param :: (Typeable a, PathPiece a) => Path (a : `[]`)
- data Path as :: [*] -> *
- renderPath :: Path l -> HVect l -> [Text]
- params :: HBuild' `[]` r => r
- class HBuild' l r where
- (==>) :: Path as -> HVectElim as a -> Dispatcher a
- dispatch :: Dispatcher a -> [Text] -> Maybe a
- data Dispatcher a
Paths
Building Paths
(</>) :: Path as -> Path bs -> Path (Append as bs) Source
Other routes can be built with /
:
docsPath = "package" </> "webcrank-dispatch-0.1" </> "docs"
param :: (Typeable a, PathPiece a) => Path (a : `[]`) Source
Paths can contain parameters. To create a parameterized path, use
param
as a path component:
docsPath :: Path '[String] docsPath = "package" </> param </> "docs"
Paths can contain as many parameters of varying types as needed:
wat :: Path '[String, Int, Bool, Int, String] wat :: "this" </> param </> param </> "crazyness" </> param </> "ends" </> param </> param
Path parameters can be of any type that have instances for
and Typeable
.PathPiece
Rendering Paths
renderPath :: Path l -> HVect l -> [Text] Source
Path
s can be rendered using
and
renderPath
.params
>>>
renderPath root params
["/"]
>>>
renderPath docsPath $ params "webcrank-dispatch-0.1"
["package", "webcrank-dispatch-0.1", "docs"]
>>>
renderPath wat $ params "down is up" 42 False 7 "up is down"
["this", "down is up", "42", "crazyness", "False", "ends", "7", "up is down"]
Note in the last example that no encoding is done by renderPath
.
Dispatching
(==>) :: Path as -> HVectElim as a -> Dispatcher a infixr 8 Source
dispatch :: Dispatcher a -> [Text] -> Maybe a Source
Dispatching requests is done with
. It turns a
dispatch
Dispatcher
into a function from a list of decoded path components
to a possible handler.
>>>
dispatch (root ==> "Welcome!") [""]
Just "Welcome!"
>>>
dispatch (root ==> "Welcome!") ["echo", "Goodbye!"]
Nothing
>>>
dispatch (root ==> "Welcome!" <> "echo" </> param ==> id) ["echo", "Goodbye!"]
Just "Goodbye!"
data Dispatcher a Source
Monoid (Dispatcher a) Source |