| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Router.DSL.AST
Description
Pure data types describing a parsed [routes| ... |] block. No Template
Haskell — this module is safe to import from both the parser (compile-time
textual layer) and the TH splice (compile-time code-generation layer).
The grammar, informally (RFC 6570 URI-template syntax for path parameters):
[routes|ControllerName
GET /posts PostsAction
POST /posts CreatePostAction
GET /posts/{postId} ShowPostAction
GET /posts/{postId}/edit EditPostAction
PATCH /posts/{postId} UpdatePostAction
DELETE /posts/{postId} DeletePostAction
|]{name} binds the segment to a record field of the same name on the
action constructor. {name:Type} is an explicit-type escape hatch.
{+name} (RFC 6570 reserved-string expansion) matches the rest of the path.
GET|POST allows multiple methods for one route. Anything after -- on a
line is a comment.
Synopsis
- data Routes = Routes {
- controllerName :: !(Maybe Text)
- routes :: ![Route]
- data Route = Route {
- routeMethods :: ![Method]
- routePath :: ![PathSeg]
- routeQueryParams :: ![Text]
- routeAction :: !ActionRef
- routeLine :: !Int
- routeKind :: !RouteKind
- data RouteKind
- data PathSeg
- data ActionRef = ActionRef {
- actionName :: !Text
- fieldBindings :: ![(Text, Text)]
- type Method = StdMethod
- methodFromText :: Text -> Maybe Method
- methodToText :: Method -> Text
- expandAnyMethod :: [Method]
Documentation
A complete parsed [routes| ... |] block.
- Single-controller — bare identifier header:
'controllerName' = Just "PostsController" - Multi-controller — empty header:
'controllerName' = Nothing. The TH splice reifies each action constructor to find its parent type and emits instances per type.
A single route: one or more methods, a path pattern, an optional query-param spec, and an action reference.
Constructors
| Route | |
Fields
| |
Whether a route is an HTTP route or a WebSocket route.
WebSocket routes are written WS /path TypeName; the right-hand
identifier is the WSApp-instance type itself (not an action
constructor), and the path must be static — no {capture} segments
and no ?query list — in this v1.
The generic ihp-router package has no notion of WSApp; it's
the IHP-side splice in IHP.Router.IHP that turns
WebSocketRoute entries into webSocketRoute calls. The kind tag
lives here so both halves of the splice can share parser output.
Constructors
| HttpRoute | |
| WebSocketRoute |
A single segment of a route path.
Constructors
| Literal !Text | A literal path piece like |
| Capture !Text !(Maybe Text) |
|
| Splat !Text !(Maybe Text) |
|
Reference to an action constructor, optionally with explicit field-to-capture bindings for when a field name in the constructor differs from the capture name in the path.
Constructors
| ActionRef | |
Fields
| |
type Method = StdMethod Source #
HTTP methods recognised by the DSL. We reuse StdMethod from
http-types rather than defining our own enum — it's the standard
type used across WAI and the rest of the Haskell HTTP ecosystem.
methodFromText :: Text -> Maybe Method Source #
Parse a method name into a Method via http-types's parseMethod.
ANY is handled by expandAnyMethod rather than here, because it
expands to all methods rather than picking one.
expandAnyMethod :: [Method] Source #
ANY expands to every StdMethod constructor.