File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed
servant-client-core/src/Servant/Client/Core
servant-client/test/Servant Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ module Servant.Client.Core.HasClient (
27
27
HasClient (.. ),
28
28
EmptyClient (.. ),
29
29
AsClientT ,
30
+ (/:) ,
30
31
foldMapUnion ,
31
32
matchUnion ,
32
33
) where
@@ -872,6 +873,37 @@ instance
872
873
873
874
#endif
874
875
876
+ infixl 1 /:
877
+
878
+ -- | Convenience function for working with nested record-clients.
879
+ --
880
+ -- Example:
881
+ --
882
+ -- @@
883
+ -- type Api = NamedAPI RootApi
884
+ --
885
+ -- data RootApi mode = RootApi
886
+ -- { subApi :: mode :- NamedAPI SubApi
887
+ -- , …
888
+ -- } deriving Generic
889
+ --
890
+ -- data SubAmi mode = SubApi
891
+ -- { endpoint :: mode :- Get '[JSON] Person
892
+ -- , …
893
+ -- } deriving Generic
894
+ --
895
+ -- api :: Proxy API
896
+ -- api = Proxy
897
+ --
898
+ -- rootClient :: RootApi (AsClientT ClientM)
899
+ -- rootClient = client api
900
+ --
901
+ -- endpointClient :: ClientM Person
902
+ -- endpointClient = client /: subApi /: endpoint
903
+ -- @@
904
+ (/:) :: a -> (a -> b ) -> b
905
+ x /: f = f x
906
+
875
907
876
908
{- Note [Non-Empty Content Types]
877
909
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module Servant.Client.Core.Reexport
8
8
, foldMapUnion
9
9
, matchUnion
10
10
, AsClientT
11
+ , (/:)
11
12
12
13
-- * Response (for @Raw@)
13
14
, Response
Original file line number Diff line number Diff line change 17
17
18
18
module Servant.GenericSpec (spec ) where
19
19
20
- import Data.Function ((&) )
21
20
import Test.Hspec
22
21
22
+ import Servant.Client ((/:) )
23
23
import Servant.ClientTestUtils
24
24
25
25
spec :: Spec
@@ -31,7 +31,7 @@ genericSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
31
31
context " Record clients work as expected" $ do
32
32
33
33
it " Client functions return expected values" $ \ (_,baseUrl) -> do
34
- runClient (recordRoutes & version) baseUrl `shouldReturn` Right 42
35
- runClient (recordRoutes & echo $ " foo" ) baseUrl `shouldReturn` Right " foo"
34
+ runClient (recordRoutes /: version) baseUrl `shouldReturn` Right 42
35
+ runClient (recordRoutes /: echo $ " foo" ) baseUrl `shouldReturn` Right " foo"
36
36
it " Clients can be nested" $ \ (_,baseUrl) -> do
37
- runClient (recordRoutes & otherRoutes & something) baseUrl `shouldReturn` Right [" foo" , " bar" , " pweet" ]
37
+ runClient (recordRoutes /: otherRoutes /: something) baseUrl `shouldReturn` Right [" foo" , " bar" , " pweet" ]
You can’t perform that action at this time.
0 commit comments