ihp-1.5.0: Haskell Web Framework
Safe HaskellNone
LanguageGHC2021

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

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 = webRoutes

class 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

Instances details
UrlCapture Segment 
Instance details

Defined in IHP.Router.Capture

UrlCapture Text 
Instance details

Defined in IHP.Router.Capture

UrlCapture Day 
Instance details

Defined in IHP.Router.Capture

UrlCapture UUID 
Instance details

Defined in IHP.Router.Capture

UrlCapture Integer 
Instance details

Defined in IHP.Router.Capture

UrlCapture Bool 
Instance details

Defined in IHP.Router.Capture

UrlCapture Int 
Instance details

Defined in IHP.Router.Capture

(Typeable table, Typeable (PrimaryKey table), UrlCapture (PrimaryKey table)) => UrlCapture (Id' table) Source #

Captures for IHP Id values route through the table's primary-key type. This works for any table whose PrimaryKey has a UrlCapture instance — UUID, Int, Integer, Text, etc.

Lives in the IHP shim so that ihp-router can ship without dragging in ModelSupport. Plain WAI users get the base instances on Text / Int / UUID etc. from IHP.Router.Capture; IHP apps get this orphan in scope automatically through import IHP.RouterPrelude.

Instance details

Defined in IHP.Router.IHP

Methods

parseCapture :: ByteString -> Maybe (Id' table) #

renderCapture :: Id' table -> Text #

newtype Segment #

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 
Instance details

Defined in IHP.Router.Capture

Eq Segment 
Instance details

Defined in IHP.Router.Capture

Methods

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

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

Ord Segment 
Instance details

Defined in IHP.Router.Capture

UrlCapture Segment 
Instance details

Defined in IHP.Router.Capture