servant-client-core 0.14 → 0.14.1
raw patch · 3 files changed
+63/−3 lines, 3 filesdep ~QuickCheckdep ~basedep ~containers
Dependency ranges changed: QuickCheck, base, containers, free, generics-sop, servant
Files
- CHANGELOG.md +8/−0
- servant-client-core.cabal +4/−3
- src/Servant/Client/Generic.hs +51/−0
CHANGELOG.md view
@@ -1,6 +1,14 @@ [The latest version of this document is on GitHub.](https://github.com/haskell-servant/servant/blob/master/servant-client-core/CHANGELOG.md) [Changelog for `servant` package contains significant entries for all core packages.](https://github.com/haskell-servant/servant/blob/master/servant/CHANGELOG.md) +0.14.1+------++- Merge in `servant-generic` (by [Patrick Chilton](https://github.com/chpatrick))+ into `servant` (`Servant.API.Generic`),+ `servant-client-code` (`Servant.Client.Generic`)+ and `servant-server` (`Servant.Server.Generic`).+ 0.14 ----
servant-client-core.cabal view
@@ -1,5 +1,5 @@ name: servant-client-core-version: 0.14+version: 0.14.1 synopsis: Core functionality and class for client function generation for servant APIs description: This library provides backend-agnostic generation of client functions. For@@ -33,6 +33,7 @@ exposed-modules: Servant.Client.Core Servant.Client.Free+ Servant.Client.Generic Servant.Client.Core.Reexport Servant.Client.Core.Internal.Auth Servant.Client.Core.Internal.BaseUrl@@ -59,7 +60,7 @@ -- Servant dependencies build-depends:- servant == 0.14.*+ servant >= 0.14.1 && <0.15 -- Other dependencies: Lower bound around what is in the latest Stackage LTS. -- Here can be exceptions if we really need features from the newer versions.@@ -67,7 +68,7 @@ base-compat >= 0.10.1 && < 0.11 , base64-bytestring >= 1.0.0.1 && < 1.1 , exceptions >= 0.10.0 && < 0.11- , free >= 5.0.2 && < 5.1+ , free >= 5.0.2 && < 5.2 , generics-sop >= 0.3.2.0 && < 0.4 , http-api-data >= 0.3.8.1 && < 0.4 , http-media >= 0.7.1.2 && < 0.8
+ src/Servant/Client/Generic.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+module Servant.Client.Generic (+ AsClientT,+ genericClient,+ genericClientHoist,+ ) where++import Data.Proxy+ (Proxy (..))++import Servant.API.Generic+import Servant.Client.Core++-- | A type that specifies that an API reocrd contains a client implementation.+data AsClientT (m :: * -> *)+instance GenericMode (AsClientT m) where+ type AsClientT m :- api = Client m api++-- | Generate a record of client functions.+genericClient+ :: forall routes m.+ ( HasClient m (ToServantApi routes)+ , GenericServant routes (AsClientT m)+ , Client m (ToServantApi routes) ~ ToServant routes (AsClientT m)+ )+ => routes (AsClientT m)+genericClient+ = fromServant+ $ clientIn (Proxy :: Proxy (ToServantApi routes)) (Proxy :: Proxy m)++-- | 'genericClient' but with 'hoistClientMonad' in between.+genericClientHoist+ :: forall routes m n.+ ( HasClient m (ToServantApi routes)+ , GenericServant routes (AsClientT n)+ , Client n (ToServantApi routes) ~ ToServant routes (AsClientT n)+ )+ => (forall x. m x -> n x) -- ^ natural transformation+ -> routes (AsClientT n)+genericClientHoist nt+ = fromServant+ $ hoistClientMonad m api nt+ $ clientIn api m+ where+ m = Proxy :: Proxy m+ api = Proxy :: Proxy (ToServantApi routes)