Introducing the new Azure SDK for C++ Beta

Introducing the new Azure SDK for C++ Beta

The new Azure SDK for C++ is idiomatic to the C++ language and ensures consistency in behavior and API surface when communicating with Azure services.

The new Azure SDK for C++ is idiomatic to the C++ language and ensures consistency in behavior and API surface when communicating with Azure services.

Some of the key features of the Azure C++ SDK are:

  • Customers of our SDK compile our source code along with their own
  • The SDK is easily consumable by environments using CMake
  • We target C++ 14 and test for x86, x64, ARM32, and ARM64 CPU architectures using gcc, clang, XCode, & MS Visual C++ compilers
  • We support Linux, Windows, and Mac platforms
  • We fully embrace exception handling to report errors from SDK methods
  • We offer very few abstractions making our code easy to understand and debug

Azure Core

At the heart of our SDK is what we refer to as Azure Core. This code defines several data types and functions for use by the client libraries that build on top of it, such as the Azure Storage Blobs client library. Here are just some of Azure Core’s features:

  • A replaceable HTTP stack allowing customers to select and use the HTTP stack that they desire. We ship a libcurl transport adapter which enables our SDK to work on all supported CPU architectures and OSes. We will soon have a WinHTTP transport adapter specifically for Windows.
  • Like our other language SDKs, Azure Core offers an HTTP pipeline of policies which can be configured at runtime.
  • All I/O operations are cancelable using our own Context mechanism.
  • We have our own easy-to-use BodyStream base class enabling the upload and download of byte streams typically used by blobs and files. Using the decorator pattern, you can create your own BodyStream-derived classes to compose features such as progress reporting, encryption, compression, and so on.

In addition to the above features, Azure Core provides features available to client libraries written to access other Azure services. Customers use these features indirectly by way of interacting with a client library. By providing these features in Azure Core, the client libraries built on top of us share a common implementation and many features behave identically across client libraries. For example, Azure Core offers a standard set of credential types and an HTTP pipeline with logging, retry, and telemetry policies.

Example Code using the C++ Storage Blob Client Library

The code below demonstrates how to create a storage blob container, create a blob in that container by uploading a data buffer in memory, and how to download the blob’s data back to a memory buffer. The comments in the code describe what is happening.

#include "azure/storage/blobs/blob.hpp"

#include <iostream>
#include <string>

using namespace Azure::Storage::Blobs;

int main()
{
  // Create a BlobContainerClient from a connection string & container name
  auto containerClient = BlobContainerClient::CreateFromConnectionString(
      "[StorageConnectionString]",
      "sample-container");
  try
  {
    containerClient.Create();  // Attempt to create the blob container
  }
  catch (std::runtime_error& e)
  {
    // The container may already exist
    std::cout << e.what() << std::endl;
    return -1;
  }

  // Create a BlockBlobClient from a container & blob name
  BlockBlobClient blobClient = containerClient.GetBlockBlobClient(
    "sample-blob");

  {
    // Create blob whose content is the specified data buffer
    std::string blobContent;
    blobContent.resize(50 * 1024ULL * 1024, 'x');  // 50 MB of x

    blobClient.UploadFrom(
        reinterpret_cast<const uint8_t*>(blobContent.data()),
        blobContent.size());
  }

  {
    // Download the blob’s contents to a data buffer
    blobClient.DownloadTo(
      reinterpret_cast<uint8_t*>(&blobContent[0]), blobContent.size());
  }

  return 0;
}

Azure SDK Releases

Azure SDK Blog Contributions

Thank you for reading this Azure SDK blog post! We hope that you learned something new and welcome you to share this post. We are open to Azure SDK blog contributions. Please contact us at [email protected] with your topic and we’ll get you setup as a guest blogger.

azure cplusplus programming developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company

Tracking a Developer’s Journey From Documentation Visit

Measuring website activity provides only half the story. See how to best track the developer's journey and what funnel stages makes sense for API-first products

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

Azure Certifications for developers | Azure Tips and Tricks

In this edition of Azure Tips and Tricks, you'll learn about the Azure Certifications for developers. For more tips and tricks,