File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1
1
{ pkgs ? import <nixpkgs> { }
2
- , compiler ? "ghc821 "
2
+ , compiler ? "ghc822 "
3
3
, tutorial ? false
4
4
} :
5
5
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module Servant.Client
9
9
, runClientM
10
10
, ClientEnv (.. )
11
11
, mkClientEnv
12
+ , hoistClient
12
13
, module Servant.Client.Core.Reexport
13
14
) where
14
15
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ spec = describe "Servant.Client" $ do
89
89
basicAuthSpec
90
90
genAuthSpec
91
91
genericClientSpec
92
+ hoistClientSpec
92
93
93
94
-- * test data types
94
95
@@ -491,6 +492,28 @@ genericClientSpec = beforeAll (startWaiApp genericClientServer) $ afterAll endWa
491
492
left show <$> runClient (getSum 3 4 ) baseUrl `shouldReturn` Right 7
492
493
left show <$> runClient doNothing baseUrl `shouldReturn` Right ()
493
494
495
+ -- * hoistClient
496
+
497
+ type HoistClientAPI = Get '[JSON ] Int :<|> Capture " n" Int :> Post '[JSON ] Int
498
+
499
+ hoistClientAPI :: Proxy HoistClientAPI
500
+ hoistClientAPI = Proxy
501
+
502
+ hoistClientServer :: Application -- implements HoistClientAPI
503
+ hoistClientServer = serve hoistClientAPI $ return 5 :<|> (\ n -> return n)
504
+
505
+ hoistClientSpec :: Spec
506
+ hoistClientSpec = beforeAll (startWaiApp hoistClientServer) $ afterAll endWaiApp $ do
507
+ describe " Servant.Client.hoistClient" $ do
508
+ it " allows us to GET/POST/... requests in IO instead of ClientM" $ \ (_, baseUrl) -> do
509
+ let (getInt :<|> postInt)
510
+ = hoistClient hoistClientAPI
511
+ (fmap (either (error . show ) id ) . flip runClient baseUrl)
512
+ (client hoistClientAPI)
513
+
514
+ getInt `shouldReturn` 5
515
+ postInt 5 `shouldReturn` 5
516
+
494
517
-- * utils
495
518
496
519
startWaiApp :: Application -> IO (ThreadId , BaseUrl )
You can’t perform that action at this time.
0 commit comments