Safe Haskell | None |
---|---|
Language | Haskell2010 |
Servant.Router
- data View
- data Location = Location {}
- data RoutingError
- data Router m a where
- RChoice :: Router m a -> Router m a -> Router m a
- RCapture :: FromHttpApiData x => (x -> Router m a) -> Router m a
- RQueryParam :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> (Maybe x -> Router m a) -> Router m a
- RQueryParams :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> ([x] -> Router m a) -> Router m a
- RQueryFlag :: KnownSymbol sym => Proxy sym -> (Bool -> Router m a) -> Router m a
- RPath :: KnownSymbol sym => Proxy sym -> Router m a -> Router m a
- RPage :: m a -> Router m a
- type family ViewTransform layout view where ...
- class HasRouter layout where
- runRouteLoc :: forall layout m a. (HasRouter layout, Monad m) => Location -> Proxy layout -> RouteT layout m a -> m (Either RoutingError a)
- runRoute :: forall layout m a. (HasRouter layout, Monad m) => String -> Proxy layout -> RouteT layout m a -> m (Either RoutingError a)
- routeLoc :: Monad m => Location -> Router m a -> m (Either RoutingError a)
- uriToLocation :: URI -> Location
Documentation
Location
is used to split the path and query of a URI into components.
data RoutingError Source #
When routing, the router may fail to match a location. Either this is an unrecoverable failure, such as failing to parse a query parameter, or it is recoverable by trying another path.
Instances
data Router m a where Source #
A Router
contains the information necessary to execute a handler.
Constructors
RChoice :: Router m a -> Router m a -> Router m a | |
RCapture :: FromHttpApiData x => (x -> Router m a) -> Router m a | |
RQueryParam :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> (Maybe x -> Router m a) -> Router m a | |
RQueryParams :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> ([x] -> Router m a) -> Router m a | |
RQueryFlag :: KnownSymbol sym => Proxy sym -> (Bool -> Router m a) -> Router m a | |
RPath :: KnownSymbol sym => Proxy sym -> Router m a -> Router m a | |
RPage :: m a -> Router m a |
type family ViewTransform layout view where ... Source #
Transform a layout by replacing View
with another type
Equations
ViewTransform (a :<|> b) view = ViewTransform a view :<|> ViewTransform b view | |
ViewTransform (a :> b) view = a :> ViewTransform b view | |
ViewTransform View view = view |
class HasRouter layout where Source #
This is similar to the HasServer
class from servant-server
.
It is the class responsible for making API combinators routable.
RuoteT
is used to build up the handler types.
Router
is returned, to be interpretted by routeLoc
.
Minimal complete definition
Methods
constHandler :: Monad m => Proxy layout -> Proxy m -> a -> RouteT layout m a Source #
Create a constant route handler that returns a
route :: Proxy layout -> Proxy m -> Proxy a -> RouteT layout m a -> Router m a Source #
Transform a route handler into a Router
.
routeConst :: Monad m => Proxy layout -> Proxy m -> a -> Router m a Source #
Create a Router
from a constant.
Instances
HasRouter * View Source # | |
(HasRouter * x, HasRouter * y) => HasRouter * ((:<|>) x y) Source # | |
(HasRouter k1 sublayout, KnownSymbol sym) => HasRouter * ((:>) * k1 (QueryFlag sym) sublayout) Source # | |
(HasRouter k1 sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter * ((:>) * k1 (QueryParams * sym x) sublayout) Source # | |
(HasRouter k1 sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter * ((:>) * k1 (QueryParam * sym x) sublayout) Source # | |
(HasRouter k1 sublayout, FromHttpApiData x) => HasRouter * ((:>) * k1 (Capture * sym x) sublayout) Source # | |
(HasRouter k1 sublayout, KnownSymbol path) => HasRouter * ((:>) Symbol k1 path sublayout) Source # | |
runRouteLoc :: forall layout m a. (HasRouter layout, Monad m) => Location -> Proxy layout -> RouteT layout m a -> m (Either RoutingError a) Source #
runRoute :: forall layout m a. (HasRouter layout, Monad m) => String -> Proxy layout -> RouteT layout m a -> m (Either RoutingError a) Source #