Search code examples
scottyhaskell-wai

How to capture multiple URL parameters / segments?


Given a url like http://test.com/abc/xyz/1/2/3, how can I retrieve all the URL segments after abc/ so the resulting value would be ["xyz","1","2","3]?


Solution

  • In case anybody stumbles upon this in future, I've managed to resolve it with:

    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
    

    And using the function function:

    get (function $ processParams "/comparePackage") $ comparePackageHandler