License | BSD3 |
---|---|
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
- data Static s
- type Root = Static ""
- data p1 :/ p2
- data Route ms r
- class Router server r pr where
- route :: (iface ~ ApiInterface server) => Proxy r -> server -> ParsedRoute pr -> RoutingApplication
- router :: (iface ~ ApiInterface server, Router server apis `(CUSTOM "", `[]`)`) => Proxy apis -> server -> RoutingApplication
- type family ToPieces r :: [*]
- type family FromPieces pps :: *
- data PathSegment
- = StaticSegment Text
- | Hole
- class MkPathFormatString r where
- mkPathFormatString :: Proxy r -> [PathSegment]
- apiHandler :: forall query p m r. (query ~ `[]`, MonadCatch (HandlerM p), ApiHandler p m r, Typeable m, Typeable r) => Tagged query p -> Request m r -> HandlerM p (Query (Response m r) query)
- type family FilterDynP ps :: [*]
- data StaticPiece s
- data DynamicPiece t
- data ParsedRoute :: (*, [*]) -> * where
- Nil :: Proxy method -> ParsedRoute `(method, `[]`)`
- ConsStaticPiece :: Proxy (p :: Symbol) -> ParsedRoute `(method, ps)` -> ParsedRoute `(method, StaticPiece p : ps)`
- ConsDynamicPiece :: !t -> ParsedRoute `(method, ps)` -> ParsedRoute `(method, DynamicPiece t : ps)`
- data PieceType :: * -> * where
- SPiece :: Proxy (p :: Symbol) -> PieceType (StaticPiece p)
- DPiece :: !val -> PieceType (DynamicPiece val)
- fromParsedRoute :: (PathParam m (FromPieces pths) ~ HListToTuple (FilterDynP pths)) => ParsedRoute `(m, pths)` -> PathParam m (FromPieces pths)
- snocParsedRoute :: ParsedRoute `(method, ps)` -> PieceType pt -> ParsedRoute `(method, ps :++ `[pt]`)`
- symTxt :: KnownSymbol sym => proxy sym -> Text
Route types
Datatype representing a static path piece.
(KnownSymbol piece, ApiHandler s m (Static piece), ToHeader (HeaderOut m (Static piece)), ToParam Cookie (CookieOut m (Static piece)), FromParam QueryParam (QueryParam m (Static piece)), FromParam FormParam (FormParam m (Static piece)), FromParam FileParam (FileParam m (Static piece)), FromHeader (HeaderIn m (Static piece)), FromParam Cookie (CookieIn m (Static piece)), Encodings (ContentTypes m (Static piece)) (ApiOut m (Static piece)), Encodings (ContentTypes m (Static piece)) (ApiErr m (Static piece)), (~) * (PathParam m (Static piece)) (), ParamErrToApiErr (ApiErr m (Static piece)), ToHListRecTuple (StripContents (RequestBody m (Static piece))), PartDecodings (RequestBody m (Static piece)), Typeable * m, Typeable * (Static piece), WebApiServer s) => Router * s (Static piece) ((,) * [*] m pp) Source | |
KnownSymbol s => MkPathFormatString (Static s) Source | |
type PathParam' m (Static s) = () Source |
Datatype representing a route.
(KnownSymbol rpiece, (~) [*] paths ((:++) * pp ((:) * (DynamicPiece lpiece) ((:) * (StaticPiece rpiece) ([] *)))), (~) [*] paths ((:++) * ((:++) * pp ((:) * (DynamicPiece lpiece) ([] *))) ((:) * (StaticPiece rpiece) ([] *))), (~) * route (FromPieces paths), ApiHandler s m route, (~) * (PathParam m route) (HListToTuple (FilterDynP paths)), FromParam QueryParam (QueryParam m route), FromParam FormParam (FormParam m route), FromParam FileParam (FileParam m route), FromParam Cookie (CookieIn m route), FromHeader (HeaderIn m route), Encodings (ContentTypes m route) (ApiErr m route), Encodings (ContentTypes m route) (ApiOut m route), ToHeader (HeaderOut m route), ToParam Cookie (CookieOut m route), DecodeParam lpiece, ParamErrToApiErr (ApiErr m route), ToHListRecTuple (StripContents (RequestBody m route)), PartDecodings (RequestBody m route), Typeable * m, Typeable * route, WebApiServer s) => Router * s ((:/) * Symbol lpiece rpiece) ((,) * [*] m pp) Source | |
(KnownSymbol lpiece, KnownSymbol rpiece, (~) [*] paths ((:++) * pp ((:) * (StaticPiece lpiece) ((:) * (StaticPiece rpiece) ([] *)))), (~) [*] paths ((:++) * ((:++) * pp ((:) * (StaticPiece lpiece) ([] *))) ((:) * (StaticPiece rpiece) ([] *))), (~) * route (FromPieces paths), ApiHandler s m route, (~) * (PathParam m route) (HListToTuple (FilterDynP paths)), FromParam QueryParam (QueryParam m route), FromParam FormParam (FormParam m route), FromParam FileParam (FileParam m route), FromParam Cookie (CookieIn m route), FromHeader (HeaderIn m route), Encodings (ContentTypes m route) (ApiErr m route), Encodings (ContentTypes m route) (ApiOut m route), ToHeader (HeaderOut m route), ToParam Cookie (CookieOut m route), ParamErrToApiErr (ApiErr m route), ToHListRecTuple (StripContents (RequestBody m route)), PartDecodings (RequestBody m route), Typeable * m, Typeable * route, WebApiServer s) => Router * s ((:/) Symbol Symbol lpiece rpiece) ((,) * [*] m pp) Source | |
(Router * s (MarkDyn rest) ((,) * [*] m ((:++) * pp ((:) * (StaticPiece piece) ([] *)))), KnownSymbol piece) => Router * s ((:/) Symbol * piece rest) ((,) * [*] m pp) Source | |
(Router * s (MarkDyn rest) ((,) * [*] m ((:++) * pp ((:) * (DynamicPiece piece) ([] *)))), DecodeParam piece) => Router * s ((:/) * * piece rest) ((,) * [*] m pp) Source | |
MkFormatStr (ToPieces * ((:/) k k1 a b)) => MkPathFormatString ((:/) k k a b) Source | |
type PathParam' m ((:/) k k1 p1 p2) = HListToTuple (FilterDynP (ToPieces * ((:/) k k1 p1 p2))) Source |
Default routing implementation
Datatype representing a endpoint.
class Router server r pr where Source
Class to do the default routing.
route :: (iface ~ ApiInterface server) => Proxy r -> server -> ParsedRoute pr -> RoutingApplication Source
router :: (iface ~ ApiInterface server, Router server apis `(CUSTOM "", `[]`)`) => Proxy apis -> server -> RoutingApplication Source
type family ToPieces r :: [*] Source
Convert the path into a flat hierarchy.
ToPieces (Static s) = `[StaticPiece s]` | |
ToPieces ((p1 :: Symbol) :/ (p2 :: Symbol)) = `[StaticPiece p1, StaticPiece p2]` | |
ToPieces ((p1 :: *) :/ (p2 :: Symbol)) = `[DynamicPiece p1, StaticPiece p2]` | |
ToPieces ((p1 :: Symbol) :/ (p2 :/ p3)) = StaticPiece p1 : ToPieces (p2 :/ p3) | |
ToPieces ((p1 :: *) :/ (p2 :/ p3)) = DynamicPiece p1 : ToPieces (p2 :/ p3) | |
ToPieces ((p1 :: *) :/ (p2 :: *)) = `[DynamicPiece p1, DynamicPiece p2]` | |
ToPieces ((p1 :: Symbol) :/ (p2 :: *)) = `[StaticPiece p1, DynamicPiece p2]` |
type family FromPieces pps :: * Source
FromPieces `[StaticPiece s]` = Static s | |
FromPieces `[StaticPiece p1, StaticPiece p2]` = p1 :/ p2 | |
FromPieces `[DynamicPiece p1, DynamicPiece p2]` = p1 :/ p2 | |
FromPieces `[StaticPiece p1, DynamicPiece p2]` = p1 :/ p2 | |
FromPieces `[DynamicPiece p1, StaticPiece p2]` = p1 :/ p2 | |
FromPieces (StaticPiece p1 : (StaticPiece p2 : pps)) = p1 :/ FromPieces (StaticPiece p2 : pps) | |
FromPieces (DynamicPiece p1 : (DynamicPiece p2 : pps)) = p1 :/ FromPieces (DynamicPiece p2 : pps) | |
FromPieces (StaticPiece p1 : (DynamicPiece p2 : pps)) = p1 :/ FromPieces (DynamicPiece p2 : pps) | |
FromPieces (DynamicPiece p1 : (StaticPiece p2 : pps)) = p1 :/ FromPieces (StaticPiece p2 : pps) |
Custom routing
data PathSegment Source
Type of segments of a Path.
StaticSegment Text | A static segment |
Hole | A dynamic segment |
class MkPathFormatString r where Source
Describe representation of the route.
mkPathFormatString :: Proxy r -> [PathSegment] Source
Given a route, this function should produce the [PathSegment]
of that route. This gives the flexibility to hook in a different routing system into the application.
KnownSymbol s => MkPathFormatString (Static s) Source | |
MkFormatStr (ToPieces * ((:/) k k1 a b)) => MkPathFormatString ((:/) k k a b) Source |
apiHandler :: forall query p m r. (query ~ `[]`, MonadCatch (HandlerM p), ApiHandler p m r, Typeable m, Typeable r) => Tagged query p -> Request m r -> HandlerM p (Query (Response m r) query) Source
This function is used to call local handler without incurring the cost of network round trip and se/deserialisation of Request and Response.
Internal
type family FilterDynP ps :: [*] Source
FilterDynP (DynamicPiece p1 : p2) = p1 : FilterDynP p2 | |
FilterDynP (p1 : p2) = FilterDynP p2 | |
FilterDynP `[]` = `[]` |
data StaticPiece s Source
data DynamicPiece t Source
((~) * route (FromPieces ((:++) * pp ((:) * (DynamicPiece t) ([] *)))), ApiHandler s m route, (~) * (PathParam m route) (HListToTuple (FilterDynP ((:++) * pp ((:) * (DynamicPiece t) ([] *))))), FromParam QueryParam (QueryParam m route), FromParam FormParam (FormParam m route), FromParam FileParam (FileParam m route), FromParam Cookie (CookieIn m route), FromHeader (HeaderIn m route), Encodings (ContentTypes m route) (ApiErr m route), Encodings (ContentTypes m route) (ApiOut m route), ToHeader (HeaderOut m route), ToParam Cookie (CookieOut m route), DecodeParam t, ParamErrToApiErr (ApiErr m route), ToHListRecTuple (StripContents (RequestBody m route)), PartDecodings (RequestBody m route), Typeable * m, Typeable * route, WebApiServer s) => Router * s (DynamicPiece t) ((,) * [*] m pp) Source |
data ParsedRoute :: (*, [*]) -> * where Source
Nil :: Proxy method -> ParsedRoute `(method, `[]`)` | |
ConsStaticPiece :: Proxy (p :: Symbol) -> ParsedRoute `(method, ps)` -> ParsedRoute `(method, StaticPiece p : ps)` | |
ConsDynamicPiece :: !t -> ParsedRoute `(method, ps)` -> ParsedRoute `(method, DynamicPiece t : ps)` |
data PieceType :: * -> * where Source
SPiece :: Proxy (p :: Symbol) -> PieceType (StaticPiece p) | |
DPiece :: !val -> PieceType (DynamicPiece val) |
fromParsedRoute :: (PathParam m (FromPieces pths) ~ HListToTuple (FilterDynP pths)) => ParsedRoute `(m, pths)` -> PathParam m (FromPieces pths) Source
snocParsedRoute :: ParsedRoute `(method, ps)` -> PieceType pt -> ParsedRoute `(method, ps :++ `[pt]`)` Source
symTxt :: KnownSymbol sym => proxy sym -> Text Source