| helics 3.6.1

RestApiConnection.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #pragma once
9
10 #include "../common/JsonProcessingFunctions.hpp"
11
12 #include <boost/asio/connect.hpp>
13 #include <boost/asio/strand.hpp>
14 #include <boost/beast/core.hpp>
15 #include <boost/beast/http.hpp>
16 #include <boost/beast/version.hpp>
17 #include <boost/container/flat_map.hpp>
18 #include <memory>
19 #include <string>
20 #include <string_view>
21 #include <vector>
22
23 namespace helics::apps {
24
25 class RestApiConnection {
26 public:
27 explicit RestApiConnection(std::string_view host = "localhost");
28
29 ~RestApiConnection();
30
31 bool connect(std::string_view server, std::string_view port);
32
33 void disconnect();
34
35 std::string sendGet(const std::string& target);
36
37 std::string sendCommand(boost::beast::http::verb command,
38 const std::string& target,
39 const std::string& body);
40
41 private:
42 boost::asio::io_context ioc;
43
44 std::unique_ptr<boost::beast::tcp_stream> stream;
45 boost::beast::flat_buffer buffer;
46
47 std::string hostName{"localHost"};
48 nlohmann::json config;
49 bool connected{false};
50 };
51 } // namespace helics::apps
helics::apps::RestApiConnection
Definition: RestApiConnection.hpp:25