如何捕获多个 URL 参数/段?
How to capture multiple URL parameters / segments?
给定一个像 http://test.com/abc/xyz/1/2/3
这样的 url,我如何才能检索 abc/
之后的所有 URL 段,以便结果值为 ["xyz","1","2","3]
?
如果将来有人偶然发现这个问题,我已经设法解决了这个问题:
processParams :: String -> Request -> Maybe [Param]
processParams s x = do
case (params', isPrefix) of
(_:paramsxs, True) -> return $ fmap (flip (,) $ "") paramsxs
_ -> Nothing
where
isPrefix = s `isPrefixOf` (convertString path) :: Bool
path = rawPathInfo x
params' = fmap convertString $ decodePathSegments path
并使用function
函数:
get (function $ processParams "/comparePackage") $ comparePackageHandler
给定一个像 http://test.com/abc/xyz/1/2/3
这样的 url,我如何才能检索 abc/
之后的所有 URL 段,以便结果值为 ["xyz","1","2","3]
?
如果将来有人偶然发现这个问题,我已经设法解决了这个问题:
processParams :: String -> Request -> Maybe [Param]
processParams s x = do
case (params', isPrefix) of
(_:paramsxs, True) -> return $ fmap (flip (,) $ "") paramsxs
_ -> Nothing
where
isPrefix = s `isPrefixOf` (convertString path) :: Bool
path = rawPathInfo x
params' = fmap convertString $ decodePathSegments path
并使用function
函数:
get (function $ processParams "/comparePackage") $ comparePackageHandler