Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions pages/integrations/sdks/cpp.mdx
Original file line number Diff line number Diff line change
@@ -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 <cstdlib>
#include "UnikraftCloudV1APIClient/api/InstancesApi.h"

using namespace cloud::unikraft::v1::api;
using namespace cloud::unikraft::v1::model;

int main() {
auto apiConfig = std::make_shared<ApiConfiguration>();
apiConfig->setBaseUrl("https://api.fra0.kraft.cloud/v1");
apiConfig->setApiKey(
"Authorization",
std::string("Bearer ") + std::getenv("UKC_TOKEN")
);

auto apiClient = std::make_shared<ApiClient>(apiConfig);
// ...
}
```

The SDK has no automatic environment variable support.
Pass the token explicitly.

## Quickstart

List all instances:

```cpp title="main.cpp"
#include <iostream>
#include <cstdlib>
#include "UnikraftCloudV1APIClient/api/InstancesApi.h"

using namespace cloud::unikraft::v1::api;

int main() {
auto apiConfig = std::make_shared<ApiConfiguration>();
apiConfig->setBaseUrl("https://api.fra0.kraft.cloud/v1");
apiConfig->setApiKey(
"Authorization",
std::string("Bearer ") + std::getenv("UKC_TOKEN")
);

auto apiClient = std::make_shared<ApiClient>(apiConfig);
InstancesApi instancesApi(apiClient);

instancesApi.getInstances({}, true)
.then([](pplx::task<std::shared_ptr<GetInstancesResponse>> 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<T>` for async execution.

## Source

The SDK source is available at
[github.com/unikraft-cloud/cpp-sdk](https://github.com/unikraft-cloud/cpp-sdk).
Loading