@@ -25,6 +25,7 @@ CanRoute (..)
25
25
, webSocketAppWithCustomPath
26
26
, onlyAllowMethods
27
27
, getMethod
28
+ , routeParam
28
29
) where
29
30
30
31
import qualified Prelude
@@ -63,6 +64,8 @@ import Data.Dynamic
63
64
import IHP.Router.Types
64
65
import IHP.WebSocket (WSApp )
65
66
import GHC.TypeLits as T
67
+ import IHP.Controller.Context
68
+ import IHP.Controller.Param
66
69
67
70
class FrontController application where
68
71
controllers :: (? applicationContext :: ApplicationContext , ? application :: application , ? context :: RequestContext ) => [Parser (IO ResponseReceived )]
@@ -807,6 +810,26 @@ parseIntegerId queryVal = let
807
810
in
808
811
rawValue >>= Just . unsafeCoerce
809
812
813
+ -- | Parses and returns an integer
814
+ -- parseRational :: (Integral a) => Parser a
815
+ -- parseRational = Attoparsec.decimal
816
+
817
+ -- | Parses a route query parameter
818
+ --
819
+ -- __Example:__
820
+ --
821
+ -- > let showPost = do
822
+ -- > string "/post"
823
+ -- > let postId = routeParam "postId"
824
+ -- > pure ShowPostAction { .. }
825
+ -- Will parse the `postId` query in `/post?postId=09b545dd-9744-4ef8-87b8-8d227f4faa1e`
826
+ --
827
+ routeParam :: (? context :: RequestContext , ParamReader paramType ) => ByteString -> paramType
828
+ routeParam paramName =
829
+ let requestContext = ? context
830
+ in
831
+ let ? context = FrozenControllerContext { requestContext = requestContext, customFields = mempty }
832
+ in param paramName
810
833
811
834
-- | Display a better error when the user missed to pass an argument to an action.
812
835
--
0 commit comments