SiddiqSoft.CosmosClient
0.8.6
dotnet add package SiddiqSoft.CosmosClient --version 0.8.6
NuGet\Install-Package SiddiqSoft.CosmosClient -Version 0.8.6
<PackageReference Include="SiddiqSoft.CosmosClient" Version="0.8.6" />
<PackageVersion Include="SiddiqSoft.CosmosClient" Version="0.8.6" />
<PackageReference Include="SiddiqSoft.CosmosClient" />
paket add SiddiqSoft.CosmosClient --version 0.8.6
#r "nuget: SiddiqSoft.CosmosClient, 0.8.6"
#:package SiddiqSoft.CosmosClient@0.8.6
#addin nuget:?package=SiddiqSoft.CosmosClient&version=0.8.6
#tool nuget:?package=SiddiqSoft.CosmosClient&version=0.8.6
CosmosClient: Azure Cosmos DB REST Client for Modern C++
Overview
CosmosClient is a header-only Modern C++23 client library for the Azure Cosmos DB REST API. Designed with nlohmann::json as a first-class API metaphor, it abstracts token signature calculation, regional endpoint resolution, payload serialization, and pagination behind a clean, expressive C++ interface.
Key Features
- JSON-First API:
nlohmann::jsonis a first-class citizen for documents, configuration, queries, and headers. - Modern C++23: Utilizes C++23 standard features (
std::format, aggregate initialization, structured bindings,std::expected). - Thread-Safe Failover & Rotation: Lock-free atomic connection rotation (
rotate(),rotateReadUri()) safe under concurrent workloads. - Header-Only: Easy integration with no compilation overhead.
- Cross-Platform: Built on top of
restcl, supporting nativeWinHTTPon Windows andlibcurlon Unix/Linux/macOS. - Full Cosmos SQL API: Complete support for Databases, Containers (Collections), Documents, SQL Queries, and Stored Procedures.
- Async Operations: Built-in non-blocking asynchronous operation dispatch via thread pool with worker exception safety.
- Auto Token Signing: Automatic HMAC-SHA256 authorization token generation for Azure Cosmos DB REST requests.
Table of Contents
Quick Start
Create Document
#include "nlohmann/json.hpp"
#include "siddiqsoft/cosmoscl.hpp"
int main() {
siddiqsoft::CosmosClient client;
// Configure client with Azure Portal connection string
client.configure({
{"connectionStrings", {"AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGhpcyBpcyBhIHNhbXBsZSBrZXk=;"}},
{"partitionKeyNames", {"/id"}}
});
// Create a new document
auto resp = client.createDocument({
.database = "mydb",
.collection = "items",
.partitionKey = "item-101",
.document = {
{"id", "item-101"},
{"name", "Modern C++ Sensor"},
{"status", "active"}
}
});
if (resp.statusCode == 201) {
std::cout << "Document created! Request Charge (RUs): " << resp.requestCharge << std::endl;
}
return 0;
}
SQL Query with Parameters
#include "nlohmann/json.hpp"
#include "siddiqsoft/cosmoscl.hpp"
int main() {
siddiqsoft::CosmosClient client;
client.configure({
{"connectionStrings", {"AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=...;"}},
{"partitionKeyNames", {"/id"}}
});
auto resp = client.queryDocuments({
.database = "mydb",
.collection = "items",
.query = "SELECT * FROM c WHERE c.status = @status",
.parameters = { {{"name", "@status"}, {"value", "active"}} }
});
if (resp.statusCode == 200) {
for (const auto& doc : resp.document["Documents"]) {
std::cout << "Doc ID: " << doc["id"] << ", Name: " << doc["name"] << std::endl;
}
}
return 0;
}
Installation
Via NuGet (Windows)
WARNING
This package has dependencies that must be satisfied via CPM / CMake when compiling.
nuget install SiddiqSoft.CosmosClient
Via CMake & CPM (Recommended)
Add to your CMakeLists.txt:
include(pack/CMakeCommonHelpers.cmake)
CPMAddPackage("gh:SiddiqSoft/CosmosClient#3.2.0")
target_link_libraries(your_target PRIVATE cosmoscl::cosmoscl)
Architecture & Modular Header Layout
CosmosClient is structured as a header-only library using a main facade header (siddiqsoft/cosmoscl.hpp) and single-responsibility sub-headers in siddiqsoft/private/:
cosmoscl.hpp: Public facade header defining theCosmosClientclass interface and including internal modules.private/cosmos_types.hpp: Global logging instance (gCLog) andCosmosOperationenum definitions.private/cosmos_endpoint.hpp:CosmosEndpointconnection string parsing and lock-free atomic URI rotation.private/cosmos_connection.hpp:CosmosConnectionstruct and atomic primary/secondary failover state.private/cosmos_response.hpp:CosmosResponseTypeandCosmosIterableResponseTyperesponse envelopes.private/cosmos_argument.hpp:CosmosArgumentTyperequest payload structure and callback type definitions.private/operations/: Single-responsibility operation headers (database_ops.hpp,collection_ops.hpp,document_ops.hpp,query_ops.hpp,region_ops.hpp).private/cosmos_serializers.hpp:nlohmann::to_json,std::formatter, andoperator<<stream helpers.
Dependencies
CosmosClient depends on lightweight header-only libraries and platform HTTP components.
See dependencies.md or docs/integration/dependencies.md for the full interactive Mermaid diagram and breakdown.
Building
# Clone repository
git clone https://github.com/SiddiqSoft/CosmosClient.git
cd CosmosClient
# Build with CMake preset
cmake --preset default
cmake --build --preset default
CMake Options
| Option | Default | Description |
|---|---|---|
cosmoscl_BUILD_TESTS |
OFF |
Build unit and integration test suite (BUILD_TESTS). |
restcl_DEBUG_TRACE |
OFF |
Enable detailed HTTP header and payload trace logging to std::cerr. |
Testing
To run tests against the local Azure Cosmos DB Emulator (using Docker or Podman):
# 1. Start the Linux vNext Emulator container
./tests/setup-emulator.sh
# 2. Build and run tests using script or CMake
./tests/build_and_test.sh debug macos
Note on Emulator Protocols (
http://vshttps://):
- vNext Linux Emulator (
azure-cosmos-emulator:vnext-latest): Serves unencrypted HTTP on port 8081 (AccountEndpoint=http://localhost:8081/;).- Windows / Classic Emulator: Serves HTTPS on port 8081 with a self-signed TLS certificate (
AccountEndpoint=https://localhost:8081/;).
Documentation
Full documentation site is built with Material MkDocs and published to GitHub Pages:
License
CosmosClient is licensed under the BSD 3-Clause License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| native | native is compatible. |
-
- nlohmann.json (>= 3.12.0)
- SiddiqSoft.asynchrony (>= 2.1.3)
- SiddiqSoft.AzureCppUtils (>= 3.2.7)
- SiddiqSoft.restcl (>= 2.3.6)
- SiddiqSoft.RunOnEnd (>= 1.4.5)
- SiddiqSoft.SplitUri (>= 3.0.3)
- SiddiqSoft.string2map (>= 2.6.1)
- SiddiqSoft.StringHelpers (>= 1.2.2)
- SiddiqSoft.TimeThis (>= 2.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.8.6 | 86 | 8/18/2026 |
| 0.8.5 | 202 | 6/10/2026 |
| 0.8.4 | 198 | 6/4/2026 |
| 0.8.3 | 216 | 5/23/2026 |
| 0.8.1 | 219 | 5/20/2026 |
| 0.7.15 | 244 | 5/4/2026 |
| 0.7.14 | 1,906 | 12/23/2021 |
| 0.7.13 | 1,774 | 12/21/2021 |
| 0.7.12 | 1,877 | 12/20/2021 |
| 0.7.11 | 1,909 | 12/20/2021 |
| 0.7.10 | 1,967 | 12/18/2021 |
| 0.7.9 | 1,863 | 12/15/2021 |
| 0.7.8 | 2,207 | 11/20/2021 |
| 0.7.7 | 2,033 | 10/11/2021 |
| 0.7.6 | 1,726 | 10/8/2021 |
| 0.7.5 | 1,963 | 10/7/2021 |
| 0.7.4 | 2,010 | 10/5/2021 |
| 0.7.3 | 1,965 | 10/5/2021 |
| 0.7.2 | 1,993 | 9/28/2021 |
| 0.7.2-pullrequest0008-0005 | 1,866 | 9/28/2021 |
Documentation is over at https://siddiqsoft.github.io/CosmosClient/