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.
Methods
clientWithRoute :: Proxy m -> Proxy api -> Request -> Client m apihoistClientMonad :: Proxy m -> Proxy api -> (forall x. mon x -> mon' x) -> Client mon api -> Client mon' api
Instances38HasClient, …
RunClient m => HasClient m EmptyAPIDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientThe 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 myApiRunClient m => HasClient m RawDefined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientPick a
Methodand 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.HasClientA client querying function for
a :<|> bwill actually hand you one function for queryingaand another one for queryingb, 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.HasClientHasClient m api => HasClient m (HttpVersion :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientUsing 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.HasClientHasClient m api => HasClient m (Description desc :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientIgnore
Descriptionin client functions.HasClient m api => HasClient m (Summary desc :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientIgnore
Summaryin client functions.HasClient m api => HasClient m (AuthProtect tag :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientHasClient m api => HasClient m (IsSecure :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientHasClient m api => HasClient m (QueryString :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientHasClient m api => HasClient m (RemoteHost :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientHasClient m api => HasClient m (Vault :> api)Defined in servant-client-core-0.20.2 · Servant.Client.Core.HasClientHasClient 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.HasClientMake the querying function append
pathto 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.HasClientIf 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.HasClientIf you use a
Headerin one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by yourHeader, 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.HasClientIf you use a
QueryParamin one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by yourQueryParam, 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.HasClientIf 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.HasClientIf you use a
Capturein one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by yourCapture. 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.HasClientIf 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 = ProxygetSourceFile :: [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.HasClientIf you use a
ReqBodyin one of your endpoints in your API, the corresponding querying function will automatically take an additional argument of the type specified by yourReqBody. 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
ToJSONinstance.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.HasClientIgnore
Fragmentin 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.HasClientHasClient 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