| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Router.Capture
Description
UrlCapture is used by the explicit-routes layer (see IHP.Router.Trie and
IHP.Router.DSL) to convert between URL path segments and typed Haskell
values. Each instance specifies how a single segment is decoded into a
value and re-encoded back into URL-safe text.
The base instances (Text, Int, Integer, UUID, Bool, Day,
Segment) live here in ihp-router and have no IHP dependency. IHP's
orphan instance lives in IHP.Router.IHP so
plain WAI users of Id'ihp-router aren't dragged into IHP's model layer.
Synopsis
- class Typeable a => UrlCapture a where
- parseCapture :: ByteString -> Maybe a
- renderCapture :: a -> Text
- newtype Segment = Segment {}
Documentation
class Typeable a => UrlCapture a where Source #
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 Source #
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 Source #
Render a typed value as URL-ready text. The caller is responsible for URL-encoding if needed.
Instances
| UrlCapture Segment Source # | |
Defined in IHP.Router.Capture Methods parseCapture :: ByteString -> Maybe Segment Source # renderCapture :: Segment -> Text Source # | |
| UrlCapture Text Source # | |
Defined in IHP.Router.Capture | |
| UrlCapture Day Source # | |
Defined in IHP.Router.Capture | |
| UrlCapture UUID Source # | |
Defined in IHP.Router.Capture | |
| UrlCapture Integer Source # | |
Defined in IHP.Router.Capture Methods parseCapture :: ByteString -> Maybe Integer Source # renderCapture :: Integer -> Text Source # | |
| UrlCapture Bool Source # | |
Defined in IHP.Router.Capture | |
| UrlCapture Int Source # | |
Defined in IHP.Router.Capture | |
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.