The C++ REST SDK ("Casablanca")

The C++ REST SDK (codename “Casablanca”) has officially been released as an open source project on CodePlex (http://casablanca.codeplex.com).

We first announced Casablanca as an incubation project on Microsoft’s DevLabs back in April of 2012. Since then we have had several releases and have seen library quickly evolve. As we added new features and received feedback from customers, it was evident that two separate entities were beginning to form. As a result, the “Casablanca” project on DevLabs has been separated into 2 different SDKs: the C++ REST SDK and the Azure SDK for C++.

The first of the two SDKs being released is the C++ REST SDK. It includes tools to quickly write modern, asynchronous C++ code that connects with REST services. We take advantage of the power and productivity offered in C++11 while providing a cross-platform solution. We currently support Windows 7, Windows 8 (Windows store and desktop applications), and Linux.

The main features in this SDK include:

Ability to create a connection to a server via a HTTP Client, send requests and handle response.

Support for construction and use of Uniform Resource Identifiers (URI).

Constructing, parsing and serializing JSON values.

Asynchronously reading/writing bytes to/from an underlying medium via Streams and Stream Buffers.

Let’s look at some code to get a glimpse of the aforementioned features in action.

This first example is a simple application that uploads a file to an HTTP Server.

#include <http_client.h>

#include<filestream.h>

#include <uri.h> using namespace concurrency::streams;

using namespace web::http::client;

using namespace web::http; int main()

{

// Open stream to file.

file_stre