Skip to content
RequestExecutor for oatpp's ApiClient based on libcurl. Supports both Sync and Async APIs.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake update installation scripts Jan 28, 2019
src
test updated to oatpp veraion 0.19.4 Apr 30, 2019
utility new module structure Jan 27, 2019
.gitignore new module structure Jan 27, 2019
CMakeLists.txt updated to oatpp veraion 0.19.4 Apr 30, 2019
LICENSE Initial commit Nov 1, 2018
README.md
azure-pipelines.yml

README.md

oatpp-curl Build Status

oatpp-curl is a wrapper over the libcurl. It adapts libcurl to be used as a RequestExecutor in the oatpp's ApiClient.
It supports all features of oatpp ApiClient together with Synchronous and Asynchronous oatpp's APIs.

More about oat++:

Requires

libcurl installed.

oatpp ApiClient ?

oatpp ApiClient is a mechanism which enables you to generate Web Api Clients in declarative manner. Under the hood it uses provided RequestExecutor (ex.: oatpp::curl::RequestExecutor) to perform http requests. Thus you are abstracted from the low-level http-client library implementation and can substitute any other http-client library at any time with zero code changes.
Roughly you may treat oatpp ApiClient as Java Retrofit for C++.

Example

This example is partially taken from oatpp-consul implementation

Declare ApiClient

Declare ApiClient for remote service using code-generation

class MyApiClient : public oatpp::web::client::ApiClient {
#include OATPP_CODEGEN_BEGIN(ApiClient)
  
  API_CLIENT_INIT(DemoApiClient)
  
  API_CALL("GET", "v1/kv/{key}", kvGet, PATH(String, key))
  API_CALL("GET", "v1/kv/{key}", kvGetInDC, PATH(String, key), QUERY(String, datacenter, "dc"))
  
  API_CALL("GET", "v1/kv/{key}?raw", kvGetRaw, PATH(String, key))
  API_CALL("GET", "v1/kv/{key}?raw&dc={dc}", kvGetRawInDC, PATH(String, key), PATH(String, datacenter, "dc"))
  
  API_CALL("PUT", "v1/kv/{key}", kvPut, PATH(String, key), BODY_STRING(String, data))
  API_CALL("PUT", "v1/kv/{key}", kvPutInDC, PATH(String, key), BODY_STRING(String, data), QUERY(String, datacenter, "dc"))
  
#include OATPP_CODEGEN_END(ApiClient)
};

Create ApiClient instance

Create MyApiClient instance and configure it to use oatpp::curl::RequestExecutor

/* Create ObjectMapper for serialization of DTOs  */
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();

/* Create oatpp-curl RequestExecutor with baseUrl */
auto requestExecutor = oatpp::curl::RequestExecutor::createShared("http://localhost:8500/");

/* Instantiate MyApiClient */
auto myApiClient = MyApiClient::createShared(requestExecutor, objectMapper);

Make calls

// like that...

auto value = myApiClient->kvGetRaw("key")->readBodyToString();
OATPP_LOGD("response", "value='%s'", value->c_str());

// or like that...

auto response = myApiClient->kvPut("key", "some-value");
if(response->statusCode == 200){
  auto body = response->readBodyToString();
  if(body && body == "true") {
    OATPP_LOGD("response", "value successfully saved");
  }
}

More

You can’t perform that action at this time.