At GoingNative in February, I emphasized the need for more modern and portable C++ libraries, including for things like RESTful web/cloud services, HTTP, JSON, and more. The goal is to find or develop modern C++ libraries that leverage C++11 features, and then submit the best for standardization.
Microsoft wants to do its part, and here’s a step in that direction.
Today I’m pleased to see Soma’s post about “C++, Cloud Services, and You” announcing the DevLabs release of Casablanca, a set of C++ libraries for Visual C++ users that start to bring the same modern conveniences already enjoyed by .NET and Node.js and Erlang users also to C++ developers on our local and cloud platforms, including modern C++ libraries for REST, HTTP, and JSON. From Soma’s announcement, adding my own emphasis and minor code edits:
Historically, we’ve lacked such simple tools for developers using C++. While there are multiple relevant native networking APIs (e.g. WinINet, WinHTTP, IXMLHttpRequest2, HTTP Server API), these are not optimized from a productivity perspective for consuming and implementing RESTful cloud services using modern C++. They don’t compose particularly well with code based on the standard C++ libraries, and they don’t take advantage of modern C++ language features and practices in their programming models.
This is where “Casablanca” comes in. “Casablanca” is a set of libraries for C++ developers, taking advantage of some recent standard language features already available through Visual Studio.
“Casablanca” aims to make it significantly easier for C++ coders to consume and implement RESTful services. It builds on lessons from .NET, from Node.js, from Erlang, and from other influencers to create a modern model that is meant to be easy to program while still being scalable, composable, and flexible.
As an example, here’s a snippet that uses the client HTTP library to search Bing for my name and output the results to the console:
http_client bing( L"http://www.bing.com/search" ); bing.request( methods::GET, L"?q=S.Somasegar" ) .then( []( http_response response ) { cout << "HTML SOURCE:" << endl << response.to_string() << endl; }) .wait();and here’s a simple web listener hosted in a console application:
listener::create( argv[1], []( http_request req ) { req.reply( status_codes::OK, "Namaste!" ); }) .listen( []{ fgetc( stdin ); } ) .wait();For those of you looking to build Azure services in C++, “Casablanca” comes with a Visual Studio wizard to set up everything up correctly. You can target both Web and Worker roles, and you can access Azure storage using the built-in C++ library bindings. […] Taking C++ to the cloud with “Casablanca” is another exciting step in that journey.
Today’s Casablanca release is as a DevLabs project, to get usability feedback and to eventually support these features in the full Visual C++ product. If you’re interested in using C++ to consume and implement cloud services, and sharing what kind of support you want and whether you think Casablanca is on the right track, please let us know in the forums.
Looking beyond Visual C++, one piece of Casablanca is already being proposed for standardization, namely the “future.then” nonblocking continuations that are required to be able to write highly responsive composable libraries – you really want all async libraries to talk about their work using the same type, and std::future already gives half of what we need (blocking synchronization) and just needs the non-blocking part too. Also being proposed as an optional layer on top of “future.then” is an “await” style of language support to make the async operations as easy to express and use in C++ as in any of the best languages in the world.
Note that there are other C++ libraries too for several of these facilities. Repeating what I said at GoingNative, we (Microsoft) don’t care whose libraries get standardized – whether ones we contribute or someone else’s. We care most that there be standard C++ libraries for these modern uses, starting with the most basic “future.then” support, and to encourage all companies and groups who have libraries in these important spaces to contribute them and take the best and make them available to C++ developers on all platforms. This is a small step in that process.