1#include <userver/utest/using_namespace_userver.hpp>
3#include <userver/easy.hpp>
4#include <userver/yaml_config/merge_schemas.hpp>
6#include <userver/clients/http/component.hpp>
7#include <userver/components/component_context.hpp>
12 static constexpr std::string_view kName =
"action-client";
14 ActionClient(
const components::ComponentConfig& config,
const components::ComponentContext& context)
16 service_url_(config
["service-url"].As<std
::string
>()),
19 auto CreateHttpRequest(std::string action)
const {
23 static yaml_config::Schema GetStaticConfigSchema() {
25 type: object
26 description: My dependencies schema
27 additionalProperties: false
28 properties:
29 service-url:
30 type: string
31 description: URL of the service to send the actions to
36 const std::string service_url_;
37 clients::http::Client& http_client_;
45 auto CreateActionRequest(std::string action)
const {
return component_.CreateHttpRequest(std::move(action)); }
47 static void RegisterOn(
easy::HttpBase& app) {
48 app
.TryAddComponent<ActionClient
>(ActionClient::kName
, "service-url: http://some-service.example/v1/action");
53 ActionClient& component_;
58int main(
int argc,
char* argv[]) {
61 easy::HttpWith<Deps>(argc, argv)
63 .Post("/log", [](
const server::
http::HttpRequest& req,
const Deps& deps) {
64 const auto& action = req
.GetArg("action");
68 return deps.CreateActionRequest(action)->
body();