ihp-1.5.0: Haskell Web Framework
Safe HaskellNone
LanguageGHC2021

IHP.Router.IHP

Description

The ihp-router package ships an IHP-free [routes|…|] quasi-quoter that emits HasPath instances and a parameterised <ctrlLower>Trie :: (Ctrl -> Application) -> RouteTrie binding per controller. Plain WAI users wire that binding into routeTrieMiddleware with their own dispatch function.

This module is the IHP-specific shim that composes on top:

  • routes / routesDec — IHP-flavoured quoter. Emits everything genericEmit produces, plus a CanRoute instance per controller (whose toControllerRoute wraps <ctrlLower>Trie runAction' in a ControllerRouteTrie) and, for lowercase-header blocks, a webRoutes :: [ControllerRoute app] binding ready for FrontController.controllers.
  • 'instance UrlCapture (Id' table)' — IHP's primary-key-driven capture. Lives here (not in ihp-router) because it needs PrimaryKey.

User code accesses the IHP-flavoured quoter as import IHP.Router.DSL (routes), which re-exports from this module. The user-visible import surface is unchanged from before the extraction.

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

routesDec :: String -> Q [Dec] Source #

Underlying TH function for the IHP-flavoured routes quoter. Composes genericEmit (HasPath + per-controller <ctrlLower>Trie bindings) with ihpEmit (IHP CanRoute instance + lowercase-header binding).

ihpRoutesDec :: String -> Q [Dec] Source #

Alias for routesDec. Exposed so callers that already use the generic genericRoutesDec have a matching named entry point on the IHP-flavoured side.

ihpEmit :: ParsedBlock -> Q [Dec] Source #

Emit the IHP-flavoured declarations on top of whatever genericEmit produces:

  • one instance CanRoute Ctrl per controller, whose toControllerRoute wraps <ctrlLower>Trie runAction' in a ControllerRouteTrie;
  • for a lowercase-header block: a top-level webRoutes :: [ControllerRoute app] binding that includes webSocketRoute @T "/path" entries for each WS route in the block alongside the regular parseRoute @Ctrl entries.

Orphan instances

(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

Methods

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

renderCapture :: Id' table -> Text #