如何捕获多个URL参数/段?

时间:2017-03-25 17:30:40

标签: scotty haskell-wai

如果有http://test.com/abc/xyz/1/2/3这样的网址,如何在abc/之后检索所有网址细分,以便得到的值为["xyz","1","2","3]

1 个答案:

答案 0 :(得分:0)

如果将来有人偶然发现这一点,我已设法解决它:

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