hyperbole-0.5.0: Interactive HTML apps using type-safe serverside Haskell
Safe HaskellSafe-Inferred
LanguageGHC2021

Web.Hyperbole.Route

Synopsis

Documentation

class Route a where Source #

Derive this class to use a sum type as a route. Constructors and Selectors map intuitively to url patterns

data AppRoute
  = Main
  | Messages
  | User UserId
  deriving (Eq, Generic)

instance Route AppRoute where
  baseRoute = Just Main
>>> routeUri Main
/
>>> routeUri (User 9)
/user/9

Minimal complete definition

Nothing

Methods

baseRoute :: Maybe a Source #

The route to use if attempting to match an empty path

default baseRoute :: (Generic a, GenRoute (Rep a)) => Maybe a Source #

matchRoute :: Path -> Maybe a Source #

Try to match a path to a route

default matchRoute :: (Generic a, GenRoute (Rep a)) => Path -> Maybe a Source #

routePath :: a -> Path Source #

Map a route to a path

default routePath :: (Generic a, Eq a, GenRoute (Rep a)) => a -> Path Source #

routeUri :: Route a => a -> URI Source #

Convert a Route to a URI

>>> routeUri (User 100)
/user/100

class GenRoute f where Source #

Automatically derive Route

Methods

genRoute :: [Text] -> Maybe (f p) Source #

genPaths :: f p -> [Text] Source #

Instances

Instances details
GenRoute (U1 :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe (U1 p) Source #

genPaths :: forall (p :: k0). U1 p -> [Text] Source #

(GenRoute a, GenRoute b) => GenRoute (a :*: b :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe ((a :*: b) p) Source #

genPaths :: forall (p :: k0). (a :*: b) p -> [Text] Source #

(GenRoute a, GenRoute b) => GenRoute (a :+: b :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe ((a :+: b) p) Source #

genPaths :: forall (p :: k0). (a :+: b) p -> [Text] Source #

Route sub => GenRoute (K1 R sub :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe (K1 R sub p) Source #

genPaths :: forall (p :: k0). K1 R sub p -> [Text] Source #

(Constructor c, GenRoute f) => GenRoute (M1 C c f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe (M1 C c f p) Source #

genPaths :: forall (p :: k0). M1 C c f p -> [Text] Source #

GenRoute f => GenRoute (M1 D c f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe (M1 D c f p) Source #

genPaths :: forall (p :: k0). M1 D c f p -> [Text] Source #

GenRoute f => GenRoute (M1 S c f :: k -> Type) Source # 
Instance details

Defined in Web.Hyperbole.Route

Methods

genRoute :: forall (p :: k0). [Text] -> Maybe (M1 S c f p) Source #

genPaths :: forall (p :: k0). M1 S c f p -> [Text] Source #

genRouteRead :: Read x => [Text] -> Maybe (K1 R x a) Source #