-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathApp.cpp
More file actions
58 lines (39 loc) · 2.17 KB
/
Copy pathApp.cpp
File metadata and controls
58 lines (39 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "AsyncExample.hpp"
#include "SimpleExample.hpp"
#include "DemoApiClient.hpp"
#include "oatpp-curl/RequestExecutor.hpp"
#include "oatpp/web/client/HttpRequestExecutor.hpp"
#include "oatpp/network/tcp/client/ConnectionProvider.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include <iostream>
std::shared_ptr<oatpp::web::client::RequestExecutor> createOatppExecutor() {
OATPP_LOGD("App", "Using Oat++ native HttpRequestExecutor.");
auto connectionProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({"httpbin.org", 80});
return oatpp::web::client::HttpRequestExecutor::createShared(connectionProvider);
}
std::shared_ptr<oatpp::web::client::RequestExecutor> createCurlExecutor() {
OATPP_LOGD("App", "Using oatpp-curl RequestExecutor.");
return oatpp::curl::RequestExecutor::createShared("http://httpbin.org/", false /* set verbose=true for dubug info */);
}
void run(){
/* Create ObjectMapper for serialization of DTOs */
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
/* Create RequestExecutor which will execute ApiClient's requests */
auto requestExecutor = createOatppExecutor(); // <-- Always use oatpp native executor where's possible.
//auto requestExecutor = createCurlExecutor(); // <-- Curl request executor
/* DemoApiClient uses DemoRequestExecutor and json::mapping::ObjectMapper */
/* ObjectMapper passed here is used for serialization of outgoing DTOs */
auto client = DemoApiClient::createShared(requestExecutor, objectMapper);
SimpleExample::runExample(client);
AsyncExample::runExample(client);
}
int main(int argc, const char * argv[]) {
oatpp::base::Environment::init();
run();
/* Print how much objects were created during app running, and what have left-probably leaked */
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
std::cout << "\nEnvironment:\n";
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
oatpp::base::Environment::destroy();
}