userver: userver/clients/http/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef USERVER_TVM2_HTTP_CLIENT
4#error Use components::Http from clients/http.hpp instead
5#endif
6
7/// @file userver/clients/http/component.hpp
8/// @brief @copybrief components::HttpClient
9
10#include <userver/clients/http/client.hpp>
11#include <userver/clients/http/client_with_plugins.hpp>
12#include <userver/clients/http/component_core.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace components {
17
18/// @ingroup userver_components
19///
20/// @brief Component that manages @ref clients::http::ClientWithPlugins.
21///
22/// Reuses @ref clients::http::ClientCore from @ref components::HttpClientCore and applies
23/// sequence of @ref clients::http::Plugin to the request.
24///
25/// Returned references to @ref clients::http::Client live for a lifetime of the
26/// component and are safe for concurrent use.
27///
28/// ## Static options of components::HttpClient :
29/// @include{doc} scripts/docs/en/components_schema/core/src/clients/http/component.md
30///
31/// Options inherited from @ref components::ComponentBase :
32/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
33///
34/// ## Static configuration example:
35///
36/// @snippet components/common_component_list_test.cpp Sample http client component config
37class HttpClient final : public ComponentBase {
38public:
39 /// @ingroup userver_component_names
40 /// @brief The default name of components::HttpClient component
41 static constexpr std::string_view kName = "http-client";
42
43 HttpClient(const ComponentConfig&, const ComponentContext&);
44
45 clients::http::Client& GetHttpClient();
46
47 static yaml_config::Schema GetStaticConfigSchema();
48
49private:
50 clients::http::ClientWithPlugins http_client_;
51};
52
53template <>
54inline constexpr bool kHasValidate<HttpClient> = true;
55
56template <>
57inline constexpr auto kConfigFileMode<HttpClient> = ConfigFileMode::kNotRequired;
58
59} // namespace components
60
61USERVER_NAMESPACE_END