Safe HaskellNone

IHP.RouterSupport

Synopsis

Documentation

class HasPath controller => CanRoute controller where Source #

Methods

parseRoute' :: (?applicationContext :: ApplicationContext, ?requestContext :: RequestContext) => Parser controller Source #

Instances

Instances details
(AutoRoute controller, Controller controller) => CanRoute controller Source # 
Instance details

Defined in IHP.RouterSupport

Methods

parseRoute' :: Parser controller Source #

CanRoute WelcomeController Source # 
Instance details

Defined in IHP.Welcome.Controller

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

Instances details
(Show controller, AutoRoute controller) => HasPath controller Source # 
Instance details

Defined in IHP.RouterSupport

Methods

pathTo :: controller -> Text Source #

HasPath WelcomeController Source # 
Instance details

Defined in IHP.Welcome.Controller

class Data controller => AutoRoute controller where Source #

Minimal complete definition

Nothing

Methods

autoRoute :: (?applicationContext :: ApplicationContext, ?requestContext :: RequestContext) => Parser controller Source #

parseArgument :: forall d. Data d => ByteString -> ByteString -> d Source #

allowedMethodsForAction :: String -> [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

Instances details
AutoRoute CodeGenController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute LogsController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute DataController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute EnumValuesController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute EnumsController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute ColumnsController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute TablesController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

AutoRoute SchemaController Source # 
Instance details

Defined in IHP.IDE.ToolServer.Routes

runAction :: forall controller. (Controller controller, ?requestContext :: RequestContext, ?controllerContext :: ControllerContext, ?modelContext :: ModelContext, FrameworkConfig) => controller -> IO ResponseReceived Source #

get :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, Typeable application, Typeable action, FrameworkConfig) => ByteString -> action -> Parser (IO ResponseReceived) 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, ?requestContext :: RequestContext, Typeable application, Typeable action, FrameworkConfig) => ByteString -> action -> Parser (IO ResponseReceived) 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 :: (Controller action, InitControllerContext application, ?application :: application, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, Typeable application, Typeable action, FrameworkConfig) => action -> Parser (IO ResponseReceived) Source #

Defines the start page for a router (when / is requested).

frontControllerToWAIApp :: forall app parent config controllerContext. (Eq app, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, FrontController app, FrameworkConfig) => app -> IO ResponseReceived -> IO ResponseReceived Source #

withPrefix :: ByteString -> [Parser ByteString b] -> Parser ByteString b Source #

type family ModelControllerMap controllerContext model Source #

Maps models to their restful controllers E.g. ModelControllerMap ControllerContext User = UsersController

class FrontController application where Source #

Methods

controllers :: (?applicationContext :: ApplicationContext, ?application :: application, ?requestContext :: RequestContext, FrameworkConfig) => [Parser (IO ResponseReceived)] Source #

Instances

Instances details
FrontController ToolServerApplication Source # 
Instance details

Defined in IHP.IDE.ToolServer

Methods

controllers :: [Parser (IO ResponseReceived)] Source #

parseRoute :: forall controller application. (?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, Controller controller, CanRoute controller, InitControllerContext application, ?application :: application, Typeable application, Data controller, FrameworkConfig) => Parser (IO ResponseReceived) Source #

catchAll :: forall action application. (?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, Controller action, InitControllerContext application, Typeable action, ?application :: application, Typeable application, Data action, FrameworkConfig) => action -> Parser (IO ResponseReceived) Source #

mountFrontController :: forall frontController application. (?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, FrontController frontController, FrameworkConfig) => frontController -> Parser (IO ResponseReceived) 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)`

parseTextArgument :: forall d. Data d => ByteString -> ByteString -> d Source #

When the arguments for your AutoRoute based actions are not UUIDs or IDs you can override the parseArgument function of your AutoRoute instance with parseTextArgument to receive them as a Text

Example:

data HelloWorldController = HelloAction { name :: Text }
    deriving (Eq, Show, Data)

instance AutoRoute HelloWorldController where
    parseArgument = parseTextArgument

parseIntArgument :: forall d. Data d => ByteString -> ByteString -> d Source #

When the arguments for your AutoRoute based actions are Integers instead of UUIDs, you can override the parseArgument function of your AutoRoute instance with parseIntArgument to receive them as a Int

Example:

data HelloWorldController = HelloAction { page :: Int }
    deriving (Eq, Show, Data)

instance AutoRoute HelloWorldController where
    parseArgument = parseIntArgument

parseUUIDArgument :: forall d. Data d => ByteString -> ByteString -> d Source #

The default implementation for parseArgument in AutoRoute.

urlTo :: (HasPath action, FrameworkConfig) => 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"

parseUUID :: Parser UUID Source #

Parses and returns an UUID

parseId :: PrimaryKey (GetTableName record) ~ UUID => Parser (Id record) Source #

Parses an UUID, afterwards wraps it in an Id

remainingText :: Parser Text Source #

Returns all the remaining text until the end of the input

parseText :: Parser Text Source #

Parses until the next /

Orphan instances

HasPath action => ConvertibleStrings action AttributeValue Source #

This instances makes it possible to write href={MyAction}/ in HSX

Instance details

Methods

convertString :: action -> AttributeValue #