From 6ea877b6901cdec896ebadc867af6ad8688de26a Mon Sep 17 00:00:00 2001 From: Jerome Jaggi Date: Fri, 13 Mar 2026 15:13:47 +0100 Subject: [PATCH] docs: add C++ SDK reference page Signed-off-by: Jerome Jaggi --- pages/integrations/sdks/cpp.mdx | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 pages/integrations/sdks/cpp.mdx diff --git a/pages/integrations/sdks/cpp.mdx b/pages/integrations/sdks/cpp.mdx new file mode 100644 index 0000000..6e0b14c --- /dev/null +++ b/pages/integrations/sdks/cpp.mdx @@ -0,0 +1,145 @@ +--- +title: C++ SDK +navigation_icon: code +--- + +:::warning + +The C++ SDK is a work in progress. +The API is subject to change and breaking changes may occur between releases. + +::: + +The Unikraft Cloud C++ SDK is an autogenerated client library based on the public OpenAPI specification. +It uses [cpprestsdk](https://github.com/Microsoft/cpprestsdk) for HTTP and async operations via `PPL` tasks. + +## Dependencies + +| Dependency | Notes | +|---|---| +| [cpprestsdk](https://github.com/Microsoft/cpprestsdk) | HTTP client and `PPL` async runtime | +| Boost (`boost-uuid`) | UUID support | +| OpenSSL | TLS | +| CMake >= 3.x | Build system | + +## Installation + +### Linux + +```bash title="" +sudo apt-get install -y \ + build-essential ca-certificates cmake \ + libcpprest-dev libssl-dev make +``` + +### macOS + +```bash title="" +brew install cpprestsdk +``` + +### Windows + +```bash title="" +vcpkg install cpprestsdk cpprestsdk:x64-windows \ + boost-uuid boost-uuid:x64-windows +``` + +## Build + +```bash title="" +git clone https://github.com/unikraft-cloud/cpp-sdk +cd cpp-sdk + +cmake \ + -DCPPREST_ROOT=/usr \ + -DCMAKE_CXX_FLAGS="-I/usr/local/opt/openssl/include" \ + -DCMAKE_MODULE_LINKER_FLAGS="-L/usr/local/opt/openssl/lib" + +make +``` + +## Authentication + +Configure authentication manually via `ApiConfiguration`: + +```cpp title="main.cpp" +#include +#include "UnikraftCloudV1APIClient/api/InstancesApi.h" + +using namespace cloud::unikraft::v1::api; +using namespace cloud::unikraft::v1::model; + +int main() { + auto apiConfig = std::make_shared(); + apiConfig->setBaseUrl("https://api.fra0.kraft.cloud/v1"); + apiConfig->setApiKey( + "Authorization", + std::string("Bearer ") + std::getenv("UKC_TOKEN") + ); + + auto apiClient = std::make_shared(apiConfig); + // ... +} +``` + +The SDK has no automatic environment variable support. +Pass the token explicitly. + +## Quickstart + +List all instances: + +```cpp title="main.cpp" +#include +#include +#include "UnikraftCloudV1APIClient/api/InstancesApi.h" + +using namespace cloud::unikraft::v1::api; + +int main() { + auto apiConfig = std::make_shared(); + apiConfig->setBaseUrl("https://api.fra0.kraft.cloud/v1"); + apiConfig->setApiKey( + "Authorization", + std::string("Bearer ") + std::getenv("UKC_TOKEN") + ); + + auto apiClient = std::make_shared(apiConfig); + InstancesApi instancesApi(apiClient); + + instancesApi.getInstances({}, true) + .then([](pplx::task> task) { + auto resp = task.get(); + if (resp && resp->getData()) { + for (auto& inst : resp->getData()->getInstances()) { + std::cout << "Name: " << inst->getName() << "\n"; + std::cout << "State: " << inst->getState() << "\n"; + std::cout << "---\n"; + } + } + }) + .wait(); + + return 0; +} +``` + +## Resources + +| API class | Operations | +|---|---| +| `InstancesApi` | `createInstance`, `getInstances`, `getInstanceByUuid`, `startInstanceByUuid`, `stopInstanceByUuid`, `stopInstances`, `deleteInstanceByUuid`, `deleteInstances`, `getInstanceLogs`, `getInstanceLogsByUuid`, `getInstanceMetrics`, `getInstanceMetricsByUuid`, `waitForInstances` | +| `VolumesApi` | Create, get, attach, detach, delete volumes | +| `ServicesApi` | Create, get, delete service groups | +| `AutoscaleApi` | Create, get, delete autoscale configurations and policies | +| `CertificatesApi` | Create, get, delete certificates | +| `ImagesApi` | Get images by tag or digest | +| `UsersApi` | Get user quotas | + +All methods return `pplx::task` for async execution. + +## Source + +The SDK source is available at +[github.com/unikraft-cloud/cpp-sdk](https://github.com/unikraft-cloud/cpp-sdk).