@@ -89,6 +89,7 @@ spec = describe "Servant.Client" $ do
8989 basicAuthSpec
9090 genAuthSpec
9191 genericClientSpec
92+ hoistClientSpec
9293
9394-- * test data types
9495
@@ -491,6 +492,28 @@ genericClientSpec = beforeAll (startWaiApp genericClientServer) $ afterAll endWa
491492 left show <$> runClient (getSum 3 4) baseUrl `shouldReturn` Right 7
492493 left show <$> runClient doNothing baseUrl `shouldReturn` Right ()
493494
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+
494517-- * utils
495518
496519startWaiApp :: Application -> IO (ThreadId, BaseUrl)