Proof of concept invoking remote ping call
This commit is contained in:
commit
49af441d48
9 changed files with 198 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.clangd
|
||||||
|
tags
|
||||||
|
compile_commands.json
|
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[submodule "subprojects/restc-cpp"]
|
||||||
|
path = subprojects/restc-cpp/restc-cpp
|
||||||
|
url = https://github.com/jgaa/restc-cpp.git
|
||||||
|
[submodule "subprojects/date"]
|
||||||
|
path = subprojects/date
|
||||||
|
url = https://github.com/HowardHinnant/date.git
|
66
main.cpp
Normal file
66
main.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
#define HAS_UNCAUGHT_EXCEPTIONS 1
|
||||||
|
|
||||||
|
#include <restc-cpp/restc-cpp.h>
|
||||||
|
#include <restc-cpp/RequestBuilder.h>
|
||||||
|
#include <boost/date_time/local_time/local_time.hpp>
|
||||||
|
#include <string>
|
||||||
|
//#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/fusion/adapted.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include "date/date.h"
|
||||||
|
|
||||||
|
namespace rc = restc_cpp;
|
||||||
|
namespace lt = boost::local_time;
|
||||||
|
|
||||||
|
namespace oro {
|
||||||
|
typedef date::sys_time<std::chrono::microseconds> timestamp_t;
|
||||||
|
|
||||||
|
struct Timestamp {
|
||||||
|
Timestamp& operator= (const std::string& str) {
|
||||||
|
std::istringstream iss(str);
|
||||||
|
date::from_stream(iss, "%FT%T%Ez", ts);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp_t ts;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Ping {
|
||||||
|
Timestamp generation_timestamp;
|
||||||
|
std::string message;
|
||||||
|
int version;
|
||||||
|
};
|
||||||
|
} //namespace oro
|
||||||
|
|
||||||
|
BOOST_FUSION_ADAPT_STRUCT(
|
||||||
|
oro::Ping,
|
||||||
|
(oro::Timestamp, generation_timestamp)
|
||||||
|
(std::string, message)
|
||||||
|
(int, version)
|
||||||
|
)
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
using date::operator<<;
|
||||||
|
|
||||||
|
auto rest_client = rc::RestClient::Create();
|
||||||
|
oro::Ping ping = rest_client->ProcessWithPromiseT<oro::Ping>([&](rc::Context& ctx) {
|
||||||
|
oro::Ping ping;
|
||||||
|
std::unique_ptr<rc::Reply> reply = rc::RequestBuilder(ctx)
|
||||||
|
.Get("https://api.originsro.org/api/v1/ping")
|
||||||
|
.Header("X-Client", "RESTC_CPP")
|
||||||
|
.Header("X-Client-Purpose", "Testing")
|
||||||
|
.Execute();
|
||||||
|
|
||||||
|
std::cout << "I got X-RateLimit-Limit: " << *reply->GetHeader("X-RateLimit-Limit") << '\n';
|
||||||
|
|
||||||
|
rc::SerializeFromJson(ping, std::move(reply));
|
||||||
|
return ping;
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
std::cout << "Response received:\n\ttimestamp: " << ping.generation_timestamp.ts;
|
||||||
|
std::cout << "\n\tmessage: " << ping.message;
|
||||||
|
std::cout << "\n\tversion: " << ping.version;
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
23
meson.build
Normal file
23
meson.build
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
project('orotool', 'cpp',
|
||||||
|
version: '0.1.0',
|
||||||
|
meson_version: '>=0.49.2',
|
||||||
|
default_options: ['buildtype=debug', 'cpp_std=gnu++17'],
|
||||||
|
license: 'GPL3+',
|
||||||
|
)
|
||||||
|
|
||||||
|
restc_cpp_dep = dependency('restc-cpp', version: '>=0.1.1',
|
||||||
|
fallback: ['restc-cpp', 'restc_cpp_dep'],
|
||||||
|
default_options: [
|
||||||
|
'restc_cpp_with_unit_tests=false',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
boost_dep = dependency('Boost', modules: ['date_time'])
|
||||||
|
|
||||||
|
date_incdir = include_directories('subprojects/date/include')
|
||||||
|
|
||||||
|
executable(meson.project_name(),
|
||||||
|
'main.cpp',
|
||||||
|
install: true,
|
||||||
|
dependencies: [restc_cpp_dep, boost_dep],
|
||||||
|
include_directories: date_incdir,
|
||||||
|
)
|
1
subprojects/date
Submodule
1
subprojects/date
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit a55f1a103b9d21a0440fde0fb9ea5cf547826af6
|
23
subprojects/restc-cpp/include/restc-cpp/meson.build
Normal file
23
subprojects/restc-cpp/include/restc-cpp/meson.build
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
conf = configuration_data()
|
||||||
|
|
||||||
|
cpp = meson.get_compiler('cpp')
|
||||||
|
|
||||||
|
conf.set('RESTC_CPP_WITH_UNIT_TESTS', get_option('restc_cpp_with_unit_tests') ? 1 : false)
|
||||||
|
conf.set('RESTC_CPP_WITH_TLS', get_option('restc_cpp_with_tls') ? 1 : false)
|
||||||
|
conf.set('RESTC_CPP_LOG_WITH_BOOST_LOG', get_option('restc_cpp_log_with_boost_log') ? 1 : false)
|
||||||
|
conf.set('RESTC_CPP_WITH_ZLIB', get_option('restc_cpp_with_zlib') ? 1 : false)
|
||||||
|
conf.set('RESTC_CPP_HAVE_BOOST_TYPEINDEX', cpp.has_header('boost/type_index.hpp') ? 1 : false)
|
||||||
|
conf.set('RESTC_CPP_LOG_JSON_SERIALIZATION', get_option('restc_cpp_log_json_serialization') ? 1 : false)
|
||||||
|
if get_option('cpp_std') == 'gnu++17' or get_option('cpp_std') == 'c++17'
|
||||||
|
conf.set('RESTC_CPP_USE_CPP17', 1)
|
||||||
|
else
|
||||||
|
conf.set('RESTC_CPP_USE_CPP17', false)
|
||||||
|
endif
|
||||||
|
conf.set('RESTC_CPP_MAX_INPUT_BUFFER_LENGTH', get_option('restc_cpp_max_input_buffer_length'))
|
||||||
|
|
||||||
|
project_config_file = configure_file(
|
||||||
|
input: config_template,
|
||||||
|
output: 'config.h',
|
||||||
|
configuration: conf,
|
||||||
|
format: 'cmake',
|
||||||
|
)
|
68
subprojects/restc-cpp/meson.build
Normal file
68
subprojects/restc-cpp/meson.build
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
project('restc-cpp', 'cpp',
|
||||||
|
version: '0.9.2',
|
||||||
|
meson_version: '>=0.49.2',
|
||||||
|
default_options: ['cpp_std=gnu++17'],
|
||||||
|
)
|
||||||
|
|
||||||
|
config_template = files('restc-cpp/config.h.template')
|
||||||
|
if get_option('restc_cpp_with_zlib')
|
||||||
|
zipreaderimpl = files('restc-cpp/src/ZipReaderImpl.cpp')
|
||||||
|
endif
|
||||||
|
compiler_opts = ['-DBOOST_COROUTINE_NO_DEPRECATION_WARNING=1']
|
||||||
|
|
||||||
|
thread_dep = dependency('threads')
|
||||||
|
boost_dep = dependency('boost',
|
||||||
|
modules: [
|
||||||
|
'system', 'program_options', 'filesystem', 'date_time',
|
||||||
|
'context', 'coroutine', 'chrono', 'log'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
if not get_option('embedded_restc_cpp')
|
||||||
|
if get_option('restc_cpp_with_zlib')
|
||||||
|
zlib_dep = dependency('zlib')
|
||||||
|
endif
|
||||||
|
if get_option('restc_cpp_with_tls')
|
||||||
|
tls_dep = dependency('OpenSSL')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
pvt_incdir = include_directories('restc-cpp/src')
|
||||||
|
pub_incdir = include_directories('restc-cpp/include', 'include')
|
||||||
|
|
||||||
|
subdir('include/restc-cpp')
|
||||||
|
|
||||||
|
restc_cpp_target = library(meson.project_name(),
|
||||||
|
'restc-cpp/src/ChunkedReaderImpl.cpp',
|
||||||
|
'restc-cpp/src/ChunkedWriterImpl.cpp',
|
||||||
|
'restc-cpp/src/IoReaderImpl.cpp',
|
||||||
|
'restc-cpp/src/IoWriterImpl.cpp',
|
||||||
|
'restc-cpp/src/PlainReaderImpl.cpp',
|
||||||
|
'restc-cpp/src/PlainWriterImpl.cpp',
|
||||||
|
'restc-cpp/src/NoBodyReaderImpl.cpp',
|
||||||
|
'restc-cpp/src/DataReaderStream.cpp',
|
||||||
|
'restc-cpp/src/RestClientImpl.cpp',
|
||||||
|
'restc-cpp/src/RequestImpl.cpp',
|
||||||
|
'restc-cpp/src/ReplyImpl.cpp',
|
||||||
|
'restc-cpp/src/ConnectionPoolImpl.cpp',
|
||||||
|
'restc-cpp/src/Url.cpp',
|
||||||
|
'restc-cpp/src/RequestBodyStringImpl.cpp',
|
||||||
|
'restc-cpp/src/RequestBodyFileImpl.cpp',
|
||||||
|
'restc-cpp/src/url_encode.cpp',
|
||||||
|
zipreaderimpl,
|
||||||
|
install: true,
|
||||||
|
include_directories: [pvt_incdir, pub_incdir],
|
||||||
|
dependencies: [zlib_dep, tls_dep, thread_dep, boost_dep],
|
||||||
|
cpp_args: compiler_opts,
|
||||||
|
)
|
||||||
|
|
||||||
|
restc_cpp_dep = declare_dependency(
|
||||||
|
link_with: restc_cpp_target,
|
||||||
|
include_directories: pub_incdir,
|
||||||
|
compile_args: compiler_opts,
|
||||||
|
dependencies: [tls_dep, thread_dep, boost_dep],
|
||||||
|
)
|
||||||
|
|
||||||
|
if get_option('restc_cpp_with_unit_tests')
|
||||||
|
#subdir('tests')
|
||||||
|
endif
|
7
subprojects/restc-cpp/meson_options.txt
Normal file
7
subprojects/restc-cpp/meson_options.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
option('restc_cpp_max_input_buffer_length', type: 'integer', value: 0x7fffffff)
|
||||||
|
option('embedded_restc_cpp', type: 'boolean', value: false)
|
||||||
|
option('restc_cpp_with_unit_tests', type: 'boolean', value: false)
|
||||||
|
option('restc_cpp_with_tls', type: 'boolean', value: true)
|
||||||
|
option('restc_cpp_log_with_boost_log', type: 'boolean', value: true)
|
||||||
|
option('restc_cpp_with_zlib', type: 'boolean', value: true)
|
||||||
|
option('restc_cpp_log_json_serialization', type: 'boolean', value: false)
|
1
subprojects/restc-cpp/restc-cpp
Submodule
1
subprojects/restc-cpp/restc-cpp
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit c2b893a3979c92ab94137203294badc1c26513cd
|
Loading…
Reference in a new issue