From a61d62dd6f263d3b3e63ee414c18cd9019937a45 Mon Sep 17 00:00:00 2001 From: Nickolay Kudasov Date: Wed, 20 Jan 2016 19:57:04 +0300 Subject: [PATCH] Support CaptureAll in servant-client and servant-mock --- servant-client/src/Servant/Client.hs | 14 ++++++++++++++ servant-mock/src/Servant/Mock.hs | 3 +++ 2 files changed, 17 insertions(+) diff --git a/servant-client/src/Servant/Client.hs b/servant-client/src/Servant/Client.hs index bab4f4a2..227eb5c5 100644 --- a/servant-client/src/Servant/Client.hs +++ b/servant-client/src/Servant/Client.hs @@ -118,6 +118,20 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient sublayout) where p = unpack (toUrlPiece val) +instance (ToHttpApiData a, HasClient sublayout) + => HasClient (CaptureAll a :> sublayout) where + + type Client (CaptureAll a :> sublayout) = + [a] -> Client sublayout + + clientWithRoute Proxy req baseurl manager vals = + clientWithRoute (Proxy :: Proxy sublayout) + (foldl' (flip appendToPath) req ps) + baseurl + manager + + where ps = map (unpack . toUrlPiece) vals + instance OVERLAPPABLE_ -- Note [Non-Empty Content Types] (MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts) diff --git a/servant-mock/src/Servant/Mock.hs b/servant-mock/src/Servant/Mock.hs index d2808be2..e071f800 100644 --- a/servant-mock/src/Servant/Mock.hs +++ b/servant-mock/src/Servant/Mock.hs @@ -114,6 +114,9 @@ instance (KnownSymbol path, HasMock rest) => HasMock (path :> rest) where instance (KnownSymbol s, FromHttpApiData a, HasMock rest) => HasMock (Capture s a :> rest) where mock _ = \_ -> mock (Proxy :: Proxy rest) +instance (FromHttpApiData a, HasMock rest) => HasMock (CaptureAll a :> rest) where + mock _ = \_ -> mock (Proxy :: Proxy rest) + instance (AllCTUnrender ctypes a, HasMock rest) => HasMock (ReqBody ctypes a :> rest) where mock _ = \_ -> mock (Proxy :: Proxy rest)