HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleservant-client-0.20.2Haskell2010

Servant.Client.Streaming

This module provides client which can automatically generate querying functions for each endpoint just from the type representing your API.

This client supports streaming operations.

  • 11 types
  • 1 class
  • 12 values
valueclient :: HasClient ClientM api => Proxy api -> Client ClientM api
#

Generates a set of client functions for an API.

Example:

type API = Capture "no" Int :> Get '[JSON] Int
       :<|> Get '[JSON] [Bool]

api :: Proxy API
api = Proxy

getInt :: Int -> ClientM Int
getBools :: ClientM [Bool]
getInt :<|> getBools = client api
newtypenewtype ClientM a
#

ClientM is the monad in which client functions run. Contains the Manager and BaseUrl used for requests in the reader environment.

Instances12Monad, Functor, Applicative, MonadIO, Alt, RunClient, …
  • Monad ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • Functor ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • Applicative ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • MonadIO ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • Alt ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming

    Try clients in order, last error is preserved.

  • RunClient ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • RunStreamingClient ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • MonadError ClientError ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • MonadReader ClientEnv ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • MonadBase IO ClientMDefined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • Generic (ClientM a)Defined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
  • type Rep (ClientM a) = Rep (ReaderT ClientEnv (ExceptT ClientError (Codensity IO)) a)Defined in servant-client-0.20.2 · Servant.Client.Internal.HttpClient.Streaming
datadata ClientEnv
#

The environment in which a request is run. The baseUrl and makeClientRequest function are used to create a http-client request. Cookies are then added to that request if a CookieJar is set on the environment. Finally the request is executed with the manager. The makeClientRequest function can be used to modify the request to execute and set values which are not specified on a servant Request like responseTimeout or redirectCount

Constructors

Instances2MonadReader
valuehoistClient
  1. :: HasClient ClientM api
  2. => Proxy api
  3. -> forall a. m a -> n a
  4. -> Client m api
  5. -> Client n api
#

Change the monad the client functions live in, by supplying a conversion function (a natural transformation to be precise).

For example, assuming you have some manager :: Manager and baseurl :: BaseUrl around:

type API = Get '[JSON] Int :<|> Capture "n" Int :> Post '[JSON] Int
api :: Proxy API
api = Proxy
getInt :: IO Int
postInt :: Int -> IO Int
getInt :<|> postInt = hoistClient api (flip runClientM cenv) (client api)
  where cenv = mkClientEnv manager baseurl
classclass RunClient m => HasClient (m :: Type -> Type) api where
#

This class lets us define how each API combinator influences the creation of an HTTP request.

Unless you are writing a new backend for servant-client-core or new combinators that you want to support client-generation, you can ignore this class.

Associated types

Methods

Instances38HasClient, …
  • RunClient m => HasClient m EmptyAPIDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    The client for EmptyAPI is simply EmptyClient.

    type MyAPI = "books" :> Get '[JSON] [Book] -- GET /books
            :<|> "nothing" :> EmptyAPI
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getAllBooks :: ClientM [Book]
    (getAllBooks :<|> EmptyClient) = client myApi
  • RunClient m => HasClient m RawDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Pick a Method and specify where the server you want to query is. You get back the full Response.

  • RunClient m => HasClient m RawMDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, TypeError (NoInstanceFor (HasClient m api))) => HasClient m apiDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (forall (n :: Type -> Type). GClient api n, HasClient m (ToServantApi api), RunClient m, ErrorIfNoGeneric api) => HasClient m (NamedRoutes api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (HasClient m a, HasClient m b) => HasClient m (a :<|> b)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    A client querying function for a :<|> b will actually hand you one function for querying a and another one for querying b, stitching them together with :<|>, which really is just like a pair.

    type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
            :<|> "books" :> ReqBody '[JSON] Book :> Post Book -- POST /books
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getAllBooks :: ClientM [Book]
    postNewBook :: Book -> ClientM Book
    (getAllBooks :<|> postNewBook) = client myApi
  • (RunClient m, ReflectMethod method) => HasClient m (NoContentVerb method)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (HttpVersion :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Using a HttpVersion combinator in your API doesn't affect the client functions.

  • HasClient m api => HasClient m (BasicAuth realm usr :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (Description desc :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Ignore Description in client functions.

  • HasClient m api => HasClient m (Summary desc :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Ignore Summary in client functions.

  • HasClient m api => HasClient m (AuthProtect tag :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (IsSecure :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (QueryString :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (RemoteHost :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m api => HasClient m (Vault :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m subapi => HasClient m (WithResource res :> subapi)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (KnownSymbol path, HasClient m api) => HasClient m (path :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Make the querying function append path to the request path.

  • (KnownSymbol sym, ToHttpApiData a, HasClient m api) => HasClient m (QueryParams sym a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a QueryParams in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument, a list of values of the type specified by your QueryParams.

    If you give an empty list, nothing will be added to the query string.

    Otherwise, this function will take care of inserting a textual representation of your values in the query string, under the same query string parameter name.

    You can control how values for your type are turned into text by specifying a ToHttpApiData instance for your type.

    Example:

    type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getBooksBy :: [Text] -> ClientM [Book]
    getBooksBy = client myApi
    -- then you can just use "getBooksBy" to query that endpoint.
    -- 'getBooksBy []' for all books
    -- 'getBooksBy ["Isaac Asimov", "Robert A. Heinlein"]'
    --   to get all books by Asimov and Heinlein
  • (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequired mods)) => HasClient m (Header' mods sym a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a Header in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by your Header, wrapped in Maybe.

    That function will take care of encoding this argument as Text in the request headers.

    All you need is for your type to have a ToHttpApiData instance.

    Example:

    newtype Referer = Referer { referrer :: Text }
      deriving (Eq, Show, Generic, ToHttpApiData)
    
               -- GET /view-my-referer
    type MyApi = "view-my-referer" :> Header "Referer" Referer :> Get '[JSON] Referer
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    viewReferer :: Maybe Referer -> ClientM Book
    viewReferer = client myApi
    -- then you can just use "viewRefer" to query that endpoint
    -- specifying Nothing or e.g Just "http://haskell.org/" as arguments
  • (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequired mods)) => HasClient m (QueryParam' mods sym a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a QueryParam in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by your QueryParam, enclosed in Maybe.

    If you give Nothing, nothing will be added to the query string.

    If you give a non-Nothing value, this function will take care of inserting a textual representation of this value in the query string.

    You can control how values for your type are turned into text by specifying a ToHttpApiData instance for your type.

    Example:

    type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getBooksBy :: Maybe Text -> ClientM [Book]
    getBooksBy = client myApi
    -- then you can just use "getBooksBy" to query that endpoint.
    -- 'getBooksBy Nothing' for all books
    -- 'getBooksBy (Just "Isaac Asimov")' to get all books by Isaac Asimov
  • (KnownSymbol sym, ToDeepQuery a, HasClient m api) => HasClient m (DeepQuery sym a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (KnownSymbol sym, HasClient m api) => HasClient m (QueryFlag sym :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a QueryFlag in one of your endpoints in your API, the corresponding querying function will automatically take an additional Bool argument.

    If you give False, nothing will be added to the query string.

    Otherwise, this function will insert a value-less query string parameter under the name associated to your QueryFlag.

    Example:

    type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getBooks :: Bool -> ClientM [Book]
    getBooks = client myApi
    -- then you can just use "getBooks" to query that endpoint.
    -- 'getBooksBy False' for all books
    -- 'getBooksBy True' to only get _already published_ books
  • (ToHttpApiData a, HasClient m api) => HasClient m (Capture' mods capture a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a Capture in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by your Capture. That function will take care of inserting a textual representation of this value at the right place in the request path.

    You can control how values for this type are turned into text by specifying a ToHttpApiData instance for your type.

    Example:

    type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getBook :: Text -> ClientM Book
    getBook = client myApi
    -- then you can just use "getBook" to query that endpoint
  • (ToHttpApiData a, HasClient m sublayout) => HasClient m (CaptureAll capture a :> sublayout)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a CaptureAll in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of a list of the type specified by your CaptureAll. That function will take care of inserting a textual representation of this value at the right place in the request path.

    You can control how these values are turned into text by specifying a ToHttpApiData instance of your type.

    Example:

    type MyAPI = "src" :> CaptureAll Text -> Get '[JSON] SourceFile
    
    myApi :: Proxy
    myApi = Proxy
    getSourceFile :: [Text] -> ClientM SourceFile
    getSourceFile = client myApi
    -- then you can use "getSourceFile" to query that endpoint
  • (MimeRender ct a, HasClient m api) => HasClient m (ReqBody' mods (ct ': cts) a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    If you use a ReqBody in one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by your ReqBody. That function will take care of encoding this argument as JSON and of using it as the request body.

    All you need is for your type to have a ToJSON instance.

    Example:

    type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    addBook :: Book -> ClientM Book
    addBook = client myApi
    -- then you can just use "addBook" to query that endpoint
  • (AtMostOneFragment api, FragmentUnique (Fragment a :> api), HasClient m api) => HasClient m (Fragment a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient

    Ignore Fragment in client functions. See https://ietf.org/rfc/rfc2616.html#section-15.1.3 for more details.

    Example:

    type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]
    
    myApi :: Proxy MyApi
    myApi = Proxy
    
    getBooks :: ClientM [Book]
    getBooks = client myApi
    -- then you can just use "getBooksBy" to query that endpoint.
    -- 'getBooks' for all books.
  • (HasClient m api, MimeRender ctype chunk, FramingRender framing, ToSourceIO chunk a) => HasClient m (StreamBody' mods framing ctype a :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, TypeError (NoInstanceForSub (HasClient m) ty)) => HasClient m (ty :> sub)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, TypeError (PartialApplication HasClient arr)) => HasClient m (arr :> sub)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, contentTypes ~ (contentType ': otherContentTypes), as ~ (a ': as'), AllMime contentTypes, ReflectMethod method, All (UnrenderResponse contentTypes) as, All HasStatus as, HasStatuses as', Unique (Statuses as)) => HasClient m (UVerb method contentTypes as)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • HasClient m subapi => HasClient m (WithNamedContext name context subapi)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, MimeUnrender ct a, BuildHeadersTo ls, KnownNat status, ReflectMethod method, cts' ~ (ct ': cts)) => HasClient m (Verb method status cts' (Headers ls a))Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts), KnownNat status) => HasClient m (Verb method status cts' a)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, BuildHeadersTo ls, ReflectMethod method, KnownNat status) => HasClient m (Verb method status cts (Headers ls NoContent))Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunClient m, ReflectMethod method, KnownNat status) => HasClient m (Verb method status cts NoContent)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunStreamingClient m, MimeUnrender ct chunk, ReflectMethod method, FramingUnrender framing, FromSourceIO chunk a) => HasClient m (Stream method status framing ct a)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • (RunStreamingClient m, MimeUnrender ct chunk, ReflectMethod method, FramingUnrender framing, FromSourceIO chunk a, BuildHeadersTo hs) => HasClient m (Stream method status framing ct (Headers hs a))Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
familytype family Client (m :: Type -> Type) api
#
Instances36Client, …
datadata BaseUrl
#

Simple data type to represent the target of HTTP requests for servant's automatically-generated clients.

Constructors

Instances12Eq, Data, Ord, Show, Generic, NFData, …
datadata ResponseF a
#
Instances8Functor, Foldable, Traversable, Eq, Show, Generic, …
datadata ClientError
#

A type representing possible errors in a request

Note that this type substantially changed in 0.12.

Constructors

Instances8Eq, Show, Generic, Exception, NFData, MonadError, …
datadata Scheme
#

URI scheme to use

Constructors

Instances7Eq, Data, Ord, Show, Generic, Lift, …
  • Eq SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • Data SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • Ord SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • Show SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • Generic SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • Lift SchemeDefined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
  • type Rep Scheme = D1 ('MetaData "Scheme" "Servant.Client.Core.BaseUrl" "servant-client-core-0.20.2-7n9f1ON2T6sQmlncz8W9t" 'False) (C1 ('MetaCons "Http" 'PrefixI 'False) U1 :+: C1 ('MetaCons "Https" 'PrefixI 'False) U1)Defined in servant-client-core-0.20.2 · Servant.Client.Core.BaseUrl
value(//) :: a -> (a -> b) -> b
#

Helper to make code using records of clients more readable.

Can be mixed with (/:) for supplying arguments.

Example:

type Api = NamedRoutes RootApi

data RootApi mode = RootApi
  { subApi :: mode :- NamedRoutes SubApi
  , …
  } deriving Generic

data SubApi mode = SubApi
  { endpoint :: mode :- Get '[JSON] Person
  , …
  } deriving Generic

api :: Proxy API
api = Proxy

rootClient :: RootApi (AsClientT ClientM)
rootClient = client api

endpointClient :: ClientM Person
endpointClient = client // subApi // endpoint
value(/:) :: (a -> b -> c) -> b -> a -> c
#

Convenience function for supplying arguments to client functions when working with records of clients.

Intended to be used in conjunction with (//).

Example:

type Api = NamedRoutes RootApi

data RootApi mode = RootApi
  { subApi :: mode :- Capture "token" String :> NamedRoutes SubApi
  , hello :: mode :- Capture "name" String :> Get '[JSON] String
  , …
  } deriving Generic

data SubApi mode = SubApi
  { endpoint :: mode :- Get '[JSON] Person
  , …
  } deriving Generic

api :: Proxy API
api = Proxy

rootClient :: RootApi (AsClientT ClientM)
rootClient = client api

hello :: String -> ClientM String
hello name = rootClient // hello /: name

endpointClient :: ClientM Person
endpointClient = client // subApi /: "foobar123" // endpoint
valueparseBaseUrl :: MonadThrow m => String -> m BaseUrl
#
Example1 expression
parseBaseUrl "api.example.com"BaseUrl {baseUrlScheme = Http, baseUrlHost = "api.example.com", baseUrlPort = 80, baseUrlPath = ""}

Note: trailing slash is removed

Example1 expression
parseBaseUrl "api.example.com/"BaseUrl {baseUrlScheme = Http, baseUrlHost = "api.example.com", baseUrlPort = 80, baseUrlPath = ""}
Example1 expression
parseBaseUrl "api.example.com/dir/"BaseUrl {baseUrlScheme = Http, baseUrlHost = "api.example.com", baseUrlPort = 80, baseUrlPath = "/dir"}
valueshowBaseUrl :: BaseUrl -> String
#
Example1 expression
showBaseUrl <$> parseBaseUrl "api.example.com""http://api.example.com"
datadata EmptyClient
#

Singleton type representing a client for an empty API.

Instances4Bounded, Enum, Eq, Show
  • Bounded EmptyClientDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • Enum EmptyClientDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • Eq EmptyClientDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • Show EmptyClientDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
valuefoldMapUnion
  1. :: All c as
  2. => Proxy c
  3. -> forall x. c x => x -> a
  4. -> Union as
  5. -> a
#

Convenience function to apply a function to an unknown union element using a type class. All elements of the union must have instances in the type class, and the function is applied unconditionally.

See also: matchUnion.

valuematchUnion :: IsMember a as => Union as -> Maybe a
#

Convenience function to extract a union element using cast, ie. return the value if the selected type happens to be the actual type of the union in this value, or Nothing otherwise.

See also: foldMapUnion.

datadata AsClientT (m :: Type -> Type)
#

A type that specifies that an API record contains a client implementation.

Instances2GenericMode, :-
  • GenericMode (AsClientT m)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient
  • type (:-) (AsClientT m) api = Client m apiDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClient