helics 3.7.0
Loading...
Searching...
No Matches
RestApiConnection.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-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
23namespace helics::apps {
24
26 public:
27 explicit RestApiConnection(std::string_view host = "localhost");
28
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
Definition RestApiConnection.hpp:25