-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | automatical derivation of querying functions for servant webservices -- -- This library lets you derive automatically Haskell functions that let -- you query each endpoint of a servant webservice. -- -- See the client section of the tutorial. -- -- CHANGELOG @package servant-client @version 0.11 module Servant.Common.BaseUrl -- | Simple data type to represent the target of HTTP requests for -- servant's automatically-generated clients. data BaseUrl BaseUrl :: Scheme -> String -> Int -> String -> BaseUrl -- | URI scheme to use [baseUrlScheme] :: BaseUrl -> Scheme -- | host (eg "haskell.org") [baseUrlHost] :: BaseUrl -> String -- | port (eg 80) [baseUrlPort] :: BaseUrl -> Int -- | path (eg "ab/c") [baseUrlPath] :: BaseUrl -> String data InvalidBaseUrlException -- | URI scheme to use data Scheme -- | http:// Http :: Scheme -- | https:// Https :: Scheme parseBaseUrl :: MonadThrow m => String -> m BaseUrl showBaseUrl :: BaseUrl -> String instance GHC.Show.Show Servant.Common.BaseUrl.InvalidBaseUrlException instance GHC.Generics.Generic Servant.Common.BaseUrl.BaseUrl instance GHC.Classes.Ord Servant.Common.BaseUrl.BaseUrl instance GHC.Show.Show Servant.Common.BaseUrl.BaseUrl instance GHC.Generics.Generic Servant.Common.BaseUrl.Scheme instance GHC.Classes.Ord Servant.Common.BaseUrl.Scheme instance GHC.Classes.Eq Servant.Common.BaseUrl.Scheme instance GHC.Show.Show Servant.Common.BaseUrl.Scheme instance GHC.Classes.Eq Servant.Common.BaseUrl.BaseUrl instance GHC.Exception.Exception Servant.Common.BaseUrl.InvalidBaseUrlException module Servant.Common.Req data ServantError FailureResponse :: UrlReq -> Status -> MediaType -> ByteString -> ServantError [failingRequest] :: ServantError -> UrlReq [responseStatus] :: ServantError -> Status [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString DecodeFailure :: String -> MediaType -> ByteString -> ServantError [decodeError] :: ServantError -> String [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString UnsupportedContentType :: MediaType -> ByteString -> ServantError [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString InvalidContentTypeHeader :: ByteString -> ByteString -> ServantError [responseContentTypeHeader] :: ServantError -> ByteString [responseBody] :: ServantError -> ByteString ConnectionError :: SomeException -> ServantError [connectionError] :: ServantError -> SomeException data UrlReq UrlReq :: BaseUrl -> Req -> UrlReq data Req Req :: Builder -> QueryText -> Maybe (RequestBody, MediaType) -> [MediaType] -> [(String, Text)] -> Req [reqPath] :: Req -> Builder [qs] :: Req -> QueryText [reqBody] :: Req -> Maybe (RequestBody, MediaType) [reqAccept] :: Req -> [MediaType] [headers] :: Req -> [(String, Text)] defReq :: Req appendToPath :: String -> Req -> Req appendToQueryString :: Text -> Maybe Text -> Req -> Req addHeader :: ToHttpApiData a => String -> a -> Req -> Req -- | Set body and media type of the request being constructed. -- -- The body is set to the given bytestring using the -- RequestBodyLBS constructor. -- | Deprecated: Use setReqBodyLBS instead setRQBody :: ByteString -> MediaType -> Req -> Req -- | Set body and media type of the request being constructed. -- -- The body is set to the given bytestring using the -- RequestBodyLBS constructor. setReqBodyLBS :: ByteString -> MediaType -> Req -> Req -- | Set body and media type of the request being constructed. setReqBody :: RequestBody -> MediaType -> Req -> Req reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request displayHttpRequest :: Method -> String data ClientEnv ClientEnv :: Manager -> BaseUrl -> ClientEnv [manager] :: ClientEnv -> Manager [baseUrl] :: ClientEnv -> BaseUrl -- | ClientM is the monad in which client functions run. Contains -- the Manager and BaseUrl used for requests in the reader -- environment. newtype ClientM a ClientM :: ReaderT ClientEnv (ExceptT ServantError IO) a -> ClientM a [runClientM'] :: ClientM a -> ReaderT ClientEnv (ExceptT ServantError IO) a -- | Try clients in order, last error is preserved. runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a) performRequest :: Method -> Req -> ClientM (Int, ByteString, MediaType, [Header], Response ByteString) performRequestCT :: MimeUnrender ct result => Proxy ct -> Method -> Req -> ClientM ([Header], result) performRequestNoBody :: Method -> Req -> ClientM [Header] catchConnectionError :: IO a -> IO (Either ServantError a) instance Control.Monad.Catch.MonadCatch Servant.Common.Req.ClientM instance Control.Monad.Catch.MonadThrow Servant.Common.Req.ClientM instance Control.Monad.Error.Class.MonadError Servant.Common.Req.ServantError Servant.Common.Req.ClientM instance Control.Monad.Reader.Class.MonadReader Servant.Common.Req.ClientEnv Servant.Common.Req.ClientM instance GHC.Generics.Generic (Servant.Common.Req.ClientM a) instance Control.Monad.IO.Class.MonadIO Servant.Common.Req.ClientM instance GHC.Base.Monad Servant.Common.Req.ClientM instance GHC.Base.Applicative Servant.Common.Req.ClientM instance GHC.Base.Functor Servant.Common.Req.ClientM instance GHC.Show.Show Servant.Common.Req.ServantError instance GHC.Classes.Eq Servant.Common.Req.ServantError instance GHC.Exception.Exception Servant.Common.Req.ServantError instance GHC.Show.Show Servant.Common.Req.UrlReq instance Control.Monad.Base.MonadBase GHC.Types.IO Servant.Common.Req.ClientM instance Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO Servant.Common.Req.ClientM instance Data.Functor.Alt.Alt Servant.Common.Req.ClientM -- | Basic Authentication for clients module Servant.Common.BasicAuth -- | Authenticate a request using Basic Authentication basicAuthReq :: BasicAuthData -> Req -> Req -- | Authentication for clients module Servant.Client.Experimental.Auth -- | For better type inference and to avoid usage of a data family, we -- newtype wrap the combination of some AuthClientData and a -- function to add authentication data to a request -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE newtype AuthenticateReq a AuthenticateReq :: (AuthClientData a, AuthClientData a -> Req -> Req) -> AuthenticateReq a [unAuthReq] :: AuthenticateReq a -> (AuthClientData a, AuthClientData a -> Req -> Req) -- | For a resource protected by authentication (e.g. AuthProtect), we need -- to provide the client with some data used to add authentication data -- to a request -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE -- | Handy helper to avoid wrapping datatypes in tuples everywhere. -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE mkAuthenticateReq :: AuthClientData a -> (AuthClientData a -> Req -> Req) -> AuthenticateReq a -- | This module provides client which can automatically generate -- querying functions for each endpoint just from the type representing -- your API. module Servant.Client -- | For a resource protected by authentication (e.g. AuthProtect), we need -- to provide the client with some data used to add authentication data -- to a request -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE -- | For better type inference and to avoid usage of a data family, we -- newtype wrap the combination of some AuthClientData and a -- function to add authentication data to a request -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE newtype AuthenticateReq a AuthenticateReq :: (AuthClientData a, AuthClientData a -> Req -> Req) -> AuthenticateReq a [unAuthReq] :: AuthenticateReq a -> (AuthClientData a, AuthClientData a -> Req -> Req) -- | client allows you to produce operations to query an API from a -- client. -- --
-- type MyApi = "books" :> Get '[JSON] [Book] -- GET /books -- :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books -- -- myApi :: Proxy MyApi -- myApi = Proxy -- -- getAllBooks :: ClientM [Book] -- postNewBook :: Book -> ClientM Book -- (getAllBooks :<|> postNewBook) = client myApi --client :: HasClient api => Proxy api -> Client api -- | This class lets us define how each API combinator influences the -- creation of an HTTP request. It's mostly an internal class, you can -- just use client. class HasClient api where type Client api :: * where { type family Client api :: *; } clientWithRoute :: HasClient api => Proxy api -> Req -> Client api -- | ClientM is the monad in which client functions run. Contains -- the Manager and BaseUrl used for requests in the reader -- environment. data ClientM a runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a) data ClientEnv ClientEnv :: Manager -> BaseUrl -> ClientEnv -- | Handy helper to avoid wrapping datatypes in tuples everywhere. -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE mkAuthenticateReq :: AuthClientData a -> (AuthClientData a -> Req -> Req) -> AuthenticateReq a data ServantError FailureResponse :: UrlReq -> Status -> MediaType -> ByteString -> ServantError [failingRequest] :: ServantError -> UrlReq [responseStatus] :: ServantError -> Status [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString DecodeFailure :: String -> MediaType -> ByteString -> ServantError [decodeError] :: ServantError -> String [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString UnsupportedContentType :: MediaType -> ByteString -> ServantError [responseContentType] :: ServantError -> MediaType [responseBody] :: ServantError -> ByteString InvalidContentTypeHeader :: ByteString -> ByteString -> ServantError [responseContentTypeHeader] :: ServantError -> ByteString [responseBody] :: ServantError -> ByteString ConnectionError :: SomeException -> ServantError [connectionError] :: ServantError -> SomeException -- | Singleton type representing a client for an empty API. data EmptyClient EmptyClient :: EmptyClient instance GHC.Enum.Enum Servant.Client.EmptyClient instance GHC.Enum.Bounded Servant.Client.EmptyClient instance GHC.Show.Show Servant.Client.EmptyClient instance GHC.Classes.Eq Servant.Client.EmptyClient instance (Servant.Client.HasClient a, Servant.Client.HasClient b) => Servant.Client.HasClient (a Servant.API.Alternative.:<|> b) instance Servant.Client.HasClient Servant.API.Empty.EmptyAPI instance forall k (capture :: GHC.Types.Symbol) a (api :: k). (GHC.TypeLits.KnownSymbol capture, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.Capture.Capture capture a Servant.API.Sub.:> api) instance forall k (capture :: GHC.Types.Symbol) a (sublayout :: k). (GHC.TypeLits.KnownSymbol capture, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Client.HasClient sublayout) => Servant.Client.HasClient (Servant.API.Capture.CaptureAll capture a Servant.API.Sub.:> sublayout) instance forall k1 ct a (method :: k1) (cts' :: [GHC.Types.*]) (cts :: [GHC.Types.*]) (status :: GHC.Types.Nat). (Servant.API.ContentTypes.MimeUnrender ct a, Servant.API.Verbs.ReflectMethod method, cts' ~ (ct : cts)) => Servant.Client.HasClient (Servant.API.Verbs.Verb method status cts' a) instance forall k1 (method :: k1) (status :: GHC.Types.Nat) (cts :: [GHC.Types.*]). Servant.API.Verbs.ReflectMethod method => Servant.Client.HasClient (Servant.API.Verbs.Verb method status cts Servant.API.ContentTypes.NoContent) instance forall k1 ct a (ls :: [*]) (method :: k1) (cts' :: [GHC.Types.*]) (cts :: [GHC.Types.*]) (status :: GHC.Types.Nat). (Servant.API.ContentTypes.MimeUnrender ct a, Servant.API.ResponseHeaders.BuildHeadersTo ls, Servant.API.Verbs.ReflectMethod method, cts' ~ (ct : cts)) => Servant.Client.HasClient (Servant.API.Verbs.Verb method status cts' (Servant.API.ResponseHeaders.Headers ls a)) instance forall k1 (ls :: [*]) (method :: k1) (status :: GHC.Types.Nat) (cts :: [GHC.Types.*]). (Servant.API.ResponseHeaders.BuildHeadersTo ls, Servant.API.Verbs.ReflectMethod method) => Servant.Client.HasClient (Servant.API.Verbs.Verb method status cts (Servant.API.ResponseHeaders.Headers ls Servant.API.ContentTypes.NoContent)) instance forall k (sym :: GHC.Types.Symbol) a (api :: k). (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.Header.Header sym a Servant.API.Sub.:> api) instance forall k (api :: k). Servant.Client.HasClient api => Servant.Client.HasClient (Network.HTTP.Types.Version.HttpVersion Servant.API.Sub.:> api) instance forall k (sym :: GHC.Types.Symbol) a (api :: k). (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.QueryParam.QueryParam sym a Servant.API.Sub.:> api) instance forall k (sym :: GHC.Types.Symbol) a (api :: k). (GHC.TypeLits.KnownSymbol sym, Web.Internal.HttpApiData.ToHttpApiData a, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.QueryParam.QueryParams sym a Servant.API.Sub.:> api) instance forall k (sym :: GHC.Types.Symbol) (api :: k). (GHC.TypeLits.KnownSymbol sym, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.QueryParam.QueryFlag sym Servant.API.Sub.:> api) instance Servant.Client.HasClient Servant.API.Raw.Raw instance forall k ct a (api :: k) (cts :: [GHC.Types.*]). (Servant.API.ContentTypes.MimeRender ct a, Servant.Client.HasClient api) => Servant.Client.HasClient (Servant.API.ReqBody.ReqBody (ct : cts) a Servant.API.Sub.:> api) instance forall k (path :: GHC.Types.Symbol) (api :: k). (GHC.TypeLits.KnownSymbol path, Servant.Client.HasClient api) => Servant.Client.HasClient (path Servant.API.Sub.:> api) instance forall k (api :: k). Servant.Client.HasClient api => Servant.Client.HasClient (Data.Vault.Lazy.Vault Servant.API.Sub.:> api) instance forall k (api :: k). Servant.Client.HasClient api => Servant.Client.HasClient (Servant.API.RemoteHost.RemoteHost Servant.API.Sub.:> api) instance forall k (api :: k). Servant.Client.HasClient api => Servant.Client.HasClient (Servant.API.IsSecure.IsSecure Servant.API.Sub.:> api) instance Servant.Client.HasClient subapi => Servant.Client.HasClient (Servant.API.WithNamedContext.WithNamedContext name context subapi) instance forall k k1 (api :: k1) (tag :: k). Servant.Client.HasClient api => Servant.Client.HasClient (Servant.API.Experimental.Auth.AuthProtect tag Servant.API.Sub.:> api) instance forall k (api :: k) (realm :: GHC.Types.Symbol) usr. Servant.Client.HasClient api => Servant.Client.HasClient (Servant.API.BasicAuth.BasicAuth realm usr Servant.API.Sub.:> api) module Servant.Client.Generic -- | This class allows us to match client structure with client functions -- produced with client without explicit pattern-matching. -- -- The client structure needs a Generic instance. -- -- Example: -- --
-- type API
-- = "foo" :> Capture "x" Int :> Get '[JSON] Int
-- :<|> "bar" :> QueryParam "a" Char :> QueryParam "b" String :> Post '[JSON] [Int]
-- :<|> Capture "nested" Int :> NestedAPI
--
-- type NestedAPI
-- = Get '[JSON] String
-- :<|> "baz" :> QueryParam "c" Char :> Post '[JSON] ()
--
-- data APIClient = APIClient
-- { getFoo :: Int -> ClientM Int
-- , postBar :: Maybe Char -> Maybe String -> ClientM [Int]
-- , mkNestedClient :: Int -> NestedClient
-- } deriving GHC.Generic
--
-- instance Generics.SOP.Generic APIClient
-- instance (Client API ~ client) => ClientLike client APIClient
--
-- data NestedClient = NestedClient
-- { getString :: ClientM String
-- , postBaz :: Maybe Char -> ClientM ()
-- } deriving GHC.Generic
--
-- instance Generics.SOP.Generic NestedClient
-- instance (Client NestedAPI ~ client) => ClientLike client NestedClient
--
-- mkAPIClient :: APIClient
-- mkAPIClient = mkClient (client (Proxy :: Proxy API))
--
--
-- By default, left-nested alternatives are expanded:
--
--
-- type API1
-- = "foo" :> Capture "x" Int :> Get '[JSON] Int
-- :<|> "bar" :> QueryParam "a" Char :> Post '[JSON] String
--
-- type API2
-- = "baz" :> QueryParam "c" Char :> Post '[JSON] ()
--
-- type API = API1 :<|> API2
--
-- data APIClient = APIClient
-- { getFoo :: Int -> ClientM Int
-- , postBar :: Maybe Char -> ClientM String
-- , postBaz :: Maybe Char -> ClientM ()
-- } deriving GHC.Generic
--
-- instance Generics.SOP.Generic APIClient
-- instance (Client API ~ client) => ClientLike client APIClient
--
-- mkAPIClient :: APIClient
-- mkAPIClient = mkClient (client (Proxy :: Proxy API))
--
--
-- If you want to define client for API1 as a separate data
-- structure, you can use genericMkClientP:
--
--
-- data APIClient1 = APIClient1
-- { getFoo :: Int -> ClientM Int
-- , postBar :: Maybe Char -> ClientM String
-- } deriving GHC.Generic
--
-- instance Generics.SOP.Generic APIClient1
-- instance (Client API1 ~ client) => ClientLike client APIClient1
--
-- data APIClient = APIClient
-- { mkAPIClient1 :: APIClient1
-- , postBaz :: Maybe Char -> ClientM ()
-- } deriving GHC.Generic
--
-- instance Generics.SOP.Generic APIClient
-- instance (Client API ~ client) => ClientLike client APIClient where
-- mkClient = genericMkClientP
--
-- mkAPIClient :: APIClient
-- mkAPIClient = mkClient (client (Proxy :: Proxy API))
--
class ClientLike client custom where mkClient = genericMkClientL
mkClient :: ClientLike client custom => client -> custom
mkClient :: (ClientLike client custom, Generic custom, Code custom ~ '[xs], GClientList client '[], GClientLikeL (ClientList client '[]) xs) => client -> custom
-- | Generate client structure from client type, expanding left-nested API
-- (done by default).
genericMkClientL :: (Generic custom, Code custom ~ '[xs], GClientList client '[], GClientLikeL (ClientList client '[]) xs) => client -> custom
-- | Generate client structure from client type, regarding left-nested API
-- clients as separate data structures.
genericMkClientP :: (Generic custom, Code custom ~ '[xs], GClientLikeP client xs) => client -> custom
instance Servant.Client.Generic.ClientLike client custom => Servant.Client.Generic.ClientLike (a -> client) (a -> custom)
instance Servant.Client.Generic.ClientLike (Servant.Common.Req.ClientM a) (Servant.Common.Req.ClientM a)
instance (Servant.Client.Generic.GClientLikeP b (y : xs), Servant.Client.Generic.ClientLike a x) => Servant.Client.Generic.GClientLikeP (a Servant.API.Alternative.:<|> b) (x : y : xs)
instance Servant.Client.Generic.ClientLike a x => Servant.Client.Generic.GClientLikeP a '[x]
instance Servant.Client.Generic.GClientLikeL '[] '[]
instance (Servant.Client.Generic.ClientLike x y, Servant.Client.Generic.GClientLikeL xs ys) => Servant.Client.Generic.GClientLikeL (x : xs) (y : ys)
instance (Servant.Client.Generic.GClientList b acc, Servant.Client.Generic.GClientList a (Servant.Client.Generic.ClientList b acc)) => Servant.Client.Generic.GClientList (a Servant.API.Alternative.:<|> b) acc
instance Servant.Client.Generic.ClientList client acc ~ (client : acc) => Servant.Client.Generic.GClientList client acc