| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Router.DSL
Description
Re-exports the IHP-flavoured routes quasi-quoter from IHP.Router.IHP
and the UrlCapture class from IHP.Router.Capture so that modules
defining routes only need a single import.
Plain WAI users (no IHP dependency) should import IHP.Router.WAI
from the ihp-router package instead — that gives the IHP-free flavour
of the same quoter (no CanRoute instance, no webRoutes binding).
Synopsis
- routes :: QuasiQuoter
- class Typeable a => UrlCapture a where
- parseCapture :: ByteString -> Maybe a
- renderCapture :: a -> Text
- newtype Segment = Segment {}
Documentation
routes :: QuasiQuoter Source #
The IHP-flavoured [routes|…|] quasi-quoter. Behaves identically
to the pre-extraction quoter — re-exports the same routesDec that
composes genericEmit with the IHP-specific ihpEmit.
Use as a top-level declaration in Web/Routes.hs:
[routes|webRoutes
GET /Posts PostsAction
GET /ShowPost?postId ShowPostAction
|]
instance FrontController WebApplication where
controllers = webRoutesclass Typeable a => UrlCapture a where #
A type that can appear as a URL path segment.
Instances provide a parseCapture for decoding a raw segment bytestring
(post-URL-decoding) into a typed value, and renderCapture for the
reverse direction when generating URLs via pathTo.
Example:
>>>parseCapture @Int "42"Just 42
>>>renderCapture (42 :: Int)"42"
Methods
parseCapture :: ByteString -> Maybe a #
Parse a single URL segment (already URL-decoded) into a typed value.
Returns Nothing if the segment cannot be interpreted as this type.
renderCapture :: a -> Text #
Render a typed value as URL-ready text. The caller is responsible for URL-encoding if needed.
Instances
| UrlCapture Segment | |
Defined in IHP.Router.Capture | |
| UrlCapture Text | |
Defined in IHP.Router.Capture | |
| UrlCapture Day | |
Defined in IHP.Router.Capture | |
| UrlCapture UUID | |
Defined in IHP.Router.Capture | |
| UrlCapture Integer | |
Defined in IHP.Router.Capture | |
| UrlCapture Bool | |
Defined in IHP.Router.Capture | |
| UrlCapture Int | |
Defined in IHP.Router.Capture | |
| (Typeable table, Typeable (PrimaryKey table), UrlCapture (PrimaryKey table)) => UrlCapture (Id' table) Source # | Captures for IHP Lives in the IHP shim so that |
Defined in IHP.Router.IHP | |
A URL path segment guaranteed to be non-empty.
Useful when a capture must not match an empty string. Plain Text captures
happily match "" (the segment between two consecutive slashes); Segment
rejects that case, which is often what you want for splat captures or
required path pieces.
Instances
| Show Segment | |
| Eq Segment | |
| Ord Segment | |
| UrlCapture Segment | |
Defined in IHP.Router.Capture | |