ihp-router-1.0.0: Trie-based routing with a Yesod-style DSL for WAI
Safe HaskellNone
LanguageGHC2021

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 Id' orphan instance lives in IHP.Router.IHP so plain WAI users of ihp-router aren't dragged into IHP's model layer.

Synopsis

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.

newtype Segment Source #

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.

Constructors

Segment 

Fields

Instances

Instances details
Show Segment Source # 
Instance details

Defined in IHP.Router.Capture

Eq Segment Source # 
Instance details

Defined in IHP.Router.Capture

Methods

(==) :: Segment -> Segment -> Bool #

(/=) :: Segment -> Segment -> Bool #

Ord Segment Source # 
Instance details

Defined in IHP.Router.Capture

UrlCapture Segment Source # 
Instance details

Defined in IHP.Router.Capture