@@ -27,6 +27,7 @@ type Api =
27 :<|> "capture" :> Capture "name" String :> Get Person
27 :<|> "capture" :> Capture "name" String :> Get Person
28 :<|> "body" :> ReqBody Person :> Post Person
28 :<|> "body" :> ReqBody Person :> Post Person
29 :<|> "param" :> QueryParam "name" String :> Get Person
29 :<|> "param" :> QueryParam "name" String :> Get Person
30+ :<|> "params" :> QueryParams "names" String :> Get [Person]
30api :: Proxy Api
31api :: Proxy Api
31api = Proxy
32api = Proxy
@@ -39,6 +40,7 @@ server = serve api (
39 Just "alice" -> return alice
40 Just "alice" -> return alice
40 Just name -> left (400, name ++ " not found")
41 Just name -> left (400, name ++ " not found")
41 Nothing -> left (400, "missing parameter"))
42 Nothing -> left (400, "missing parameter"))
43+ :<|> (\ names -> return (zipWith Person names [0..]))
44withServer :: (URIAuth -> IO a) -> IO a
46withServer :: (URIAuth -> IO a) -> IO a
@@ -48,7 +50,13 @@ getGet :: URIAuth -> EitherT String IO Person
48getCapture :: String -> URIAuth -> EitherT String IO Person
50getCapture :: String -> URIAuth -> EitherT String IO Person
49getBody :: Person -> URIAuth -> EitherT String IO Person
51getBody :: Person -> URIAuth -> EitherT String IO Person
50getQueryParam :: Maybe String -> URIAuth -> EitherT String IO Person
52getQueryParam :: Maybe String -> URIAuth -> EitherT String IO Person
53+getQueryParams :: [String] -> URIAuth -> EitherT String IO [Person]
51−(getGet :<|> getCapture :<|> getBody :<|> getQueryParam) = client api
57+ :<|> getQueryParam
53spec :: Spec
61spec :: Spec
@@ -67,6 +75,11 @@ spec = do
67 Left result <- runEitherT (getQueryParam (Just "bob") host)
75 Left result <- runEitherT (getQueryParam (Just "bob") host)
68 result `shouldContain` "bob not found"
76 result `shouldContain` "bob not found"
78+ it "Servant.API.QueryParam.QueryParams" $ withServer $ \ host -> do
79+ runEitherT (getQueryParams [] host) `shouldReturn` Right []
80+ runEitherT (getQueryParams ["alice", "bob"] host)
81+ `shouldReturn` Right [Person "alice" 0, Person "bob" 1]
70 context "client correctly handles error status codes" $ do
83 context "client correctly handles error status codes" $ do
71 let test :: WrappedApi -> Spec
84 let test :: WrappedApi -> Spec
72 test (WrappedApi api) =
85 test (WrappedApi api) =