Safe Haskell | Safe-Inferred |
---|
IHP.RouterSupport
Contents
Synopsis
- class HasPath controller => CanRoute controller where
- parseRoute' :: (?context :: RequestContext) => Parser controller
- class HasPath controller where
- class Data controller => AutoRoute controller where
- autoRouteWithIdType :: (?context :: RequestContext, Data idType) => (ByteString -> Maybe idType) -> Parser controller
- autoRoute :: (?context :: RequestContext) => Parser controller
- allowedMethodsForAction :: ByteString -> [StdMethod]
- runAction :: forall controller. (Controller controller, ?context :: ControllerContext, ?modelContext :: ModelContext, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext) => controller -> IO ResponseReceived
- get :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => ByteString -> action -> RouteParser
- post :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => ByteString -> action -> RouteParser
- startPage :: forall action application controller. (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => action -> RouteParser
- frontControllerToWAIApp :: forall app. (?applicationContext :: ApplicationContext, ?context :: RequestContext, FrontController app) => app -> [RouteParser] -> IO ResponseReceived -> IO ResponseReceived
- withPrefix :: ByteString -> [Parser ByteString b] -> Parser ByteString b
- class FrontController application where
- controllers :: forall controller. (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext) => [RouteParser]
- router :: (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext) => [RouteParser] -> RouteParser
- defaultRouter :: (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext, FrontController application) => [RouteParser] -> RouteParser
- parseRoute :: forall controller application. (?applicationContext :: ApplicationContext, ?context :: RequestContext, Controller controller, CanRoute controller, InitControllerContext application, ?application :: application, Typeable application, Data controller) => RouteParser
- catchAll :: forall action application. (?applicationContext :: ApplicationContext, ?context :: RequestContext, Controller action, InitControllerContext application, Typeable action, ?application :: application, Typeable application, Data action) => action -> RouteParser
- mountFrontController :: forall frontController. (?applicationContext :: ApplicationContext, ?context :: RequestContext, FrontController frontController) => frontController -> RouteParser
- createAction :: forall controller. AutoRoute controller => Maybe controller
- updateAction :: forall controller id. AutoRoute controller => Maybe (id -> controller)
- urlTo :: (?context :: context, ConfigProvider context, HasPath action) => action -> Text
- parseUUID :: Parser UUID
- parseId :: PrimaryKey table ~ UUID => Parser (Id' table)
- parseIntegerId :: Data idType => ByteString -> Maybe idType
- remainingText :: Parser Text
- parseText :: Parser Text
- webSocketApp :: forall webSocketApp application controller. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp) => RouteParser
- webSocketAppWithCustomPath :: forall webSocketApp application controller. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp) => ByteString -> RouteParser
- webSocketAppWithHTTPFallback :: forall webSocketApp application. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp, Controller webSocketApp) => RouteParser
- onlyAllowMethods :: (?context :: RequestContext) => [StdMethod] -> Parser ()
- getMethod :: (?context :: RequestContext) => Parser StdMethod
- routeParam :: (?context :: RequestContext, ParamReader paramType) => ByteString -> paramType
- putContextRouter :: forall value. Typeable value => value -> RouteParser -> RouteParser
- type RouteParser = Parser RouteParseResult
Documentation
class HasPath controller => CanRoute controller where Source #
Methods
parseRoute' :: (?context :: RequestContext) => Parser controller Source #
Instances
CanRoute ApiController Source # | |
Defined in IHP.DataSync.REST.Routes Methods parseRoute' :: Parser ApiController Source # | |
CanRoute SitemapController Source # | |
Defined in IHP.SEO.Sitemap.Routes Methods parseRoute' :: Parser SitemapController Source # | |
CanRoute WelcomeController Source # | |
Defined in IHP.Welcome.Controller Methods parseRoute' :: Parser WelcomeController Source # | |
(AutoRoute controller, Controller controller) => CanRoute controller Source # | |
Defined in IHP.RouterSupport Methods parseRoute' :: Parser controller Source # | |
CanRoute (JobsDashboardController authType jobs) Source # | |
Defined in IHP.Job.Dashboard.Types Methods parseRoute' :: Parser (JobsDashboardController authType jobs) Source # |
class HasPath controller where Source #
Methods
pathTo :: controller -> Text Source #
Returns the path to a given action
>>>
pathTo UsersAction
"/Users"
>>>
pathTo ShowUserAction { userId = "a32913dd-ef80-4f3e-9a91-7879e17b2ece" }
"/ShowUser?userId=a32913dd-ef80-4f3e-9a91-7879e17b2ece"
Instances
HasPath ApiController Source # | |
Defined in IHP.DataSync.REST.Routes Methods pathTo :: ApiController -> Text Source # | |
HasPath SitemapController Source # | |
Defined in IHP.SEO.Sitemap.Routes Methods pathTo :: SitemapController -> Text Source # | |
HasPath WelcomeController Source # | |
Defined in IHP.Welcome.Controller Methods pathTo :: WelcomeController -> Text Source # | |
(Show controller, AutoRoute controller) => HasPath controller Source # | |
Defined in IHP.RouterSupport | |
HasPath (JobsDashboardController authType jobs) Source # | |
Defined in IHP.Job.Dashboard.Types Methods pathTo :: JobsDashboardController authType jobs -> Text Source # |
class Data controller => AutoRoute controller where Source #
Minimal complete definition
Nothing
Methods
autoRouteWithIdType :: (?context :: RequestContext, Data idType) => (ByteString -> Maybe idType) -> Parser controller Source #
autoRoute :: (?context :: RequestContext) => Parser controller Source #
allowedMethodsForAction :: ByteString -> [StdMethod] Source #
Specifies the allowed HTTP methods for a given action
The default implementation does a smart guess based on the usual naming conventions for controllers.
Example (for default implementation):
>>>
allowedMethodsForAction @ProjectsController "DeleteProjectAction"
[DELETE]
>>>
allowedMethodsForAction @ProjectsController "UpdateProjectAction"
[POST, PATCH]
>>>
allowedMethodsForAction @ProjectsController "CreateProjectAction"
[POST]
>>>
allowedMethodsForAction @ProjectsController "ShowProjectAction"
[GET, HEAD]
>>>
allowedMethodsForAction @ProjectsController "HelloAction"
[GET, POST, HEAD]
Instances
runAction :: forall controller. (Controller controller, ?context :: ControllerContext, ?modelContext :: ModelContext, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext) => controller -> IO ResponseReceived Source #
get :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => ByteString -> action -> RouteParser Source #
Routes a given path to an action when requested via GET.
Example:
instance FrontController WebApplication where controllers = [ get "/my-custom-page" NewSessionAction ]
The request GET /my-custom-page
is now executing NewSessionAction
Also see post
.
post :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => ByteString -> action -> RouteParser Source #
Routes a given path to an action when requested via POST.
Example:
instance FrontController WebApplication where controllers = [ post "/do-something" DoSomethingAction ]
The request POST /do-something
is now executing DoSomethingAction
Also see get
.
startPage :: forall action application controller. (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable action) => action -> RouteParser Source #
Defines the start page for a router (when /
is requested).
frontControllerToWAIApp :: forall app. (?applicationContext :: ApplicationContext, ?context :: RequestContext, FrontController app) => app -> [RouteParser] -> IO ResponseReceived -> IO ResponseReceived Source #
withPrefix :: ByteString -> [Parser ByteString b] -> Parser ByteString b Source #
class FrontController application where Source #
Minimal complete definition
Methods
controllers :: forall controller. (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext) => [RouteParser] Source #
router :: (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext) => [RouteParser] -> RouteParser Source #
Instances
FrontController ToolServerApplication Source # | |
Defined in IHP.IDE.ToolServer Methods controllers :: forall {k} (controller :: k). (?applicationContext :: ApplicationContext, ?application :: ToolServerApplication, ?context :: RequestContext) => [RouteParser] Source # router :: [RouteParser] -> RouteParser Source # |
defaultRouter :: (?applicationContext :: ApplicationContext, ?application :: application, ?context :: RequestContext, FrontController application) => [RouteParser] -> RouteParser Source #
parseRoute :: forall controller application. (?applicationContext :: ApplicationContext, ?context :: RequestContext, Controller controller, CanRoute controller, InitControllerContext application, ?application :: application, Typeable application, Data controller) => RouteParser Source #
catchAll :: forall action application. (?applicationContext :: ApplicationContext, ?context :: RequestContext, Controller action, InitControllerContext application, Typeable action, ?application :: application, Typeable application, Data action) => action -> RouteParser Source #
mountFrontController :: forall frontController. (?applicationContext :: ApplicationContext, ?context :: RequestContext, FrontController frontController) => frontController -> RouteParser Source #
createAction :: forall controller. AutoRoute controller => Maybe controller Source #
Returns the create action for a given controller. Example: `createAction @UsersController == Just CreateUserAction`
updateAction :: forall controller id. AutoRoute controller => Maybe (id -> controller) Source #
Returns the update action when given a controller and id. Example: `updateAction @UsersController == Just (id -> UpdateUserAction id)`
urlTo :: (?context :: context, ConfigProvider context, HasPath action) => action -> Text Source #
Returns the url to a given action.
Uses the baseUrl configured in Config/Config.hs
. When no baseUrl
is configured in development mode, it will automatically detect the
correct baseUrl
value.
>>>
urlTo UsersAction
"http://localhost:8000/Users"
>>>
urlTo ShowUserAction { userId = "a32913dd-ef80-4f3e-9a91-7879e17b2ece" }
"http://localhost:8000/ShowUser?userId=a32913dd-ef80-4f3e-9a91-7879e17b2ece"
parseId :: PrimaryKey table ~ UUID => Parser (Id' table) Source #
Parses an UUID, afterwards wraps it in an Id
parseIntegerId :: Data idType => ByteString -> Maybe idType Source #
remainingText :: Parser Text Source #
Returns all the remaining text until the end of the input
webSocketApp :: forall webSocketApp application controller. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp) => RouteParser Source #
Routes to a given WebSocket app if the path matches the WebSocket app name
Example:
instance FrontController WebApplication where controllers = [ webSocketApp @AutoRefreshWSApp ]
The request /AutoRefreshWSApp
will call the AutoRefreshWSApp
webSocketAppWithCustomPath :: forall webSocketApp application controller. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp) => ByteString -> RouteParser Source #
Routes to a given WebSocket app if the path matches
Example:
instance FrontController WebApplication where controllers = [ webSocketAppWithCustomPath @AutoRefreshWSApp "my-ws-app" ]
The request /my-ws-app
will call the AutoRefreshWSApp
webSocketAppWithHTTPFallback :: forall webSocketApp application. (WSApp webSocketApp, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?context :: RequestContext, Typeable application, Typeable webSocketApp, Controller webSocketApp) => RouteParser Source #
onlyAllowMethods :: (?context :: RequestContext) => [StdMethod] -> Parser () Source #
Filter methods when writing a custom routing parser
Example:
instance CanRoute ApiController where parseRoute' = do string "/api/" let createRecordAction = do onlyAllowMethods [POST] table <- parseText endOfInput pure CreateRecordAction { table } updateRecordAction = do onlyAllowMethods [PATCH] table <- parseText string "/" id <- parseUUID pure UpdateRecordAction { table, id } createRecordAction <|> updateRecordAction
getMethod :: (?context :: RequestContext) => Parser StdMethod Source #
Parses the HTTP Method from the request and returns it.
routeParam :: (?context :: RequestContext, ParamReader paramType) => ByteString -> paramType Source #
Parses and returns an integer parseRational :: (Integral a) => Parser a parseRational = Attoparsec.decimal
Parses a route query parameter
Example:
let showPost = do string "/post" let postId = routeParam "postId" pure ShowPostAction { .. }
Will parse the postId
query in `/post?postId=09b545dd-9744-4ef8-87b8-8d227f4faa1e`
putContextRouter :: forall value. Typeable value => value -> RouteParser -> RouteParser Source #
type RouteParser = Parser RouteParseResult Source #
Orphan instances
HasPath action => ConvertibleStrings action AttributeValue Source # | This instances makes it possible to write |
Methods convertString :: action -> AttributeValue # |