HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleservant-client-core-0.20.2Haskell2010

Servant.Client.Core.Reexport

This module is a utility for servant-client-core backend writers. It contains all the functionality from servant-client-core that should be re-exported.

  • 9 types
  • 1 class
  • 6 values

HasClient

6 declarations
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
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
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

Response (for Raw)

3 declarations
datadata ResponseF a
#
Instances8Functor, Foldable, Traversable, Eq, Show, Generic, …

Data types

2 declarations
datadata ClientError
#

A type representing possible errors in a request

Note that this type substantially changed in 0.12.

Constructors

Instances6Eq, Show, Generic, Exception, NFData, Rep
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

BaseUrl

5 declarations
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 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
valueshowBaseUrl :: BaseUrl -> String
#
Example1 expression
showBaseUrl <$> parseBaseUrl "api.example.com""http://api.example.com"
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"}