Spock-browser
Safe HaskellNone
LanguageHaskell2010

Web.Spock.Browser

Description

Typed routes shared by native tests and GHC's JavaScript backend. Use Web.Spock.Browser.History to attach a compiled router to browser navigation.

Synopsis

Documentation

type Routes = RegistryT IO () () () IO () Source #

A registry of navigation handlers, using the same typed captures as Spock.

data Router Source #

A compiled registry. dispatch executes its first matching handler.

route :: forall (as :: [Type]) (ps :: PathState). Path as ps -> HVectElim as (IO ()) -> Routes Source #

Register a route. Handler arguments follow the typed path captures.

compileRoutes :: SlashPolicy -> Routes -> IO Router Source #

Compile definitions once. IgnoreSlashes is Spock's compatibility policy. StrictSlashes preserves empty segments. RedirectTrailingSlashes uses strict matching here; canonical HTTP redirects belong to the server adapter.

dispatch :: Router -> Location -> IO Bool Source #

Run the first match, returning False when no route matched. Handler exceptions propagate; no alternative handler runs after a successful match.

data Location Source #

A validated local URL. Query and fragment remain encoded, with their leading ? and #. Path captures are percent-decoded once, segment by segment, so an encoded slash remains inside its captured value.

Constructors

Location 

Fields

Instances

Instances details
Show Location Source # 
Instance details

Defined in Web.Spock.Browser

Methods

showsPrec :: Int -> Location -> ShowS

show :: Location -> String

showList :: [Location] -> ShowS

Eq Location Source # 
Instance details

Defined in Web.Spock.Browser

Methods

(==) :: Location -> Location -> Bool

(/=) :: Location -> Location -> Bool

data NavigationError Source #

Failures omit the rejected URL and any sensitive query values.

Instances

Instances details
Show NavigationError Source # 
Instance details

Defined in Web.Spock.Browser

Methods

showsPrec :: Int -> NavigationError -> ShowS

show :: NavigationError -> String

showList :: [NavigationError] -> ShowS

Eq NavigationError Source # 
Instance details

Defined in Web.Spock.Browser

Methods

(==) :: NavigationError -> NavigationError -> Bool

(/=) :: NavigationError -> NavigationError -> Bool

parseLocation :: Text -> Either NavigationError Location Source #

Parse an absolute local path with optional query/fragment. Reject external origins, malformed escapes/UTF-8, and dot segments browsers would normalize.

renderPath :: forall (as :: [Type]). AllHave ToHttpApiData as => SlashPolicy -> Path as 'Open -> HVect as -> Either NavigationError Text Source #

Render a safe local href using the same path and slash policy as the registry. Values are encoded as complete segments, including extensions.

data Path (as :: [Type]) (pathState :: PathState) #

Instances

Instances details
(a ~ ('[] :: [Type]), pathState ~ 'Open) => IsString (Path a pathState) # 
Instance details

Defined in Web.Routing.Combinators

Methods

fromString :: String -> Path a pathState

data PathState #

Constructors

Open 
Closed 

root :: Path ('[] :: [Type]) 'Open #

The root of a path piece. Use to define a handler for "/"

static :: String -> Path ('[] :: [Type]) 'Open #

A static route piece. One leading slash is optional. Empty internal and trailing pieces are retained for strict routing; compatibility routing and renderRoute ignore them. Use renderRouteWith with the application's policy.

var :: (Typeable a, FromHttpApiData a) => Path '[a] 'Open #

A route parameter

wildcard :: Path '[Text] 'Closed #

Matches the rest of the route. Should be the last part of the path.

trailingSlash :: forall (as :: [Type]). Path as 'Open -> Path as 'Open #

Require a trailing slash in strict routing, including after a capture. Root remains root, and a path already ending in a slash is unchanged.

(<//>) :: forall (as :: [Type]) (bs :: [Type]) (ps :: PathState). Path as 'Open -> Path bs ps -> Path (Append as bs) ps infixl 5 Source #

Append path components, using Spock's familiar operator spelling.

(<.>) :: forall (as :: [Type]) (bs :: [Type]). Path as 'Open -> Path bs 'Open -> Path (Append as bs) 'Open infixl 8 #

Join the last segment on the left and the first on the right with a dot. Both sides may contain typed captures: var . "txt" or var . var. Matching tries the rightmost dot first and accepts the first split whose typed parsers and literals succeed. Use a custom capture type to restrict extensions; a Text capture accepts any text, including an empty extension. Static routes take precedence over extensions, then plain captures and wildcards. More literal characters give an extension pattern priority.

data SlashPolicy #

How empty path segments are treated. The compatibility default ignores every empty segment. Strict policies preserve internal and trailing slashes. Redirects are performed by the HTTP adapter, using strict registry matching.

Instances

Instances details
Read SlashPolicy # 
Instance details

Defined in Web.Routing.SafeRouting

Methods

readsPrec :: Int -> ReadS SlashPolicy

readList :: ReadS [SlashPolicy]

readPrec :: ReadPrec SlashPolicy

readListPrec :: ReadPrec [SlashPolicy]

Show SlashPolicy # 
Instance details

Defined in Web.Routing.SafeRouting

Methods

showsPrec :: Int -> SlashPolicy -> ShowS

show :: SlashPolicy -> String

showList :: [SlashPolicy] -> ShowS

Eq SlashPolicy # 
Instance details

Defined in Web.Routing.SafeRouting

Methods

(==) :: SlashPolicy -> SlashPolicy -> Bool

(/=) :: SlashPolicy -> SlashPolicy -> Bool