Microsoft open-source C ++ rest SDK

Source: Internet
Author: User

Microsoft's c ++ rest SDK, codenamed Casablanca, is open-source based on the Apache license. It is described as "Microsoft uses modern asynchronous C ++ API design to support cloud-based client/server communication with native code ". This product is implemented using C ++ 11. Microsoft hopes to provide a simpler method for compiling the HTTP code of the client.

Casablanca supports multiple platforms. Besides Windows 7 and Windows 8, it also supports Linux. Artur laksberg, a Microsoft developer, mentioned that support for WINXP and Vista is under development. Another highlight of this product is its support for asynchronous operations. Microsoft provided some examples to illustrate the use of Casablanca. One is to upload files through HTTP and the other is to create JSON objects.

Both Windows and Linux versions support the following features:

  • You can create a connection to the server through an HTTP client, and send requests and handle responses.
  • Supports URI construction and use.
  • Ability to build, parse, and serialize JSON values.
  • You can use stream and stream buffer to asynchronously read and write data on the underlying media.

Casablanca provides several different stream and stream buffering services: memory-based producer/consumer, file, memory-based stream that can be used with STL containers, bare pointer stream, and interoperability stream. Stream interoperability allows "Casablanca to provide two groups of classes, one using the asynchronous stream interface and the other using the iostream interface to the asynchronous stream ".

Linux HTTP clients still have some limitations because they do not yet support https, proxy, and authentication, but Microsoft says these features will be included in future versions. The source code of Casablanca is stored on codeplex, which can be viewed online or obtained through git. You can also download the latest snapshot version in the form of a zip package.

C ++ rest SDK is included in the Casablanca project. Casablanca is a local C ++ library designed to help developers C ++ applications access cloud services. If you want to write a responsive C ++ client application or an extensible server solution, try Casablanca. In addition to the C ++ rest SDK, the Casablanca project also contains the azure SDK for C ++.

The C ++ rest SDK contains some tools to help developers quickly compile modern, asynchronous, and restful C ++ applications,It complies with the c ++ 11 standard and currently supports Windows 7, Windows 8 (including Windows Store and desktop applications), and Linux.

The SDK has the following features:

  • Allows you to create server connections through HTTP clients, send requests, and process responses.
  • Supports the construction and use of Uri (Uniform resource identifiers, unified resource identifier)
  • Construct, parse, and serialize JSON values
  • Asynchronously reads/writes bytes from the underlying media through streams and stream buffers

The following example demonstrates how to upload a file to an HTTP server:

 

# Include # 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_stream <unsigned char>: open_istream (L "myfile.txt"). Then ([] (basic_istream <unsigned char> filestream)
{
// Make HTTP request with the file stream as the body. http_client client (L "http://www.myhttpserver.com ");
Client. Request (Methods: Put, l "myfile", filestream). Then ([filestream] (http_response response)
{
Filestream. Close ();
// Perform actions here to inspect the HTTP response... If (response. status_code () = status_codes: OK)
{
}
});
});

Return 0;
}

The following example demonstrates how to build and traverse JSON values:

#include <json.h>int main (){  // Create a JSON object.   json::value obj;  obj[L"key1"] = json::value::boolean (false);  obj[L"key2"] = json::value::number (44);  obj[L"key3"] = json::value::number (43.6);  obj[L"key4"] = json::value::string(U("str"));  // Loop over each element in the object. for(auto iter = obj.cbegin (); iter != obj.cend (); ++iter)  {    // Make sure to get the value as const reference otherwise you will end up copying    // the whole JSON value recursively which can be expensive if it is a nested object. const json::value &str = iter->first;    const json::value &v = iter->second;    // Perform actions here to process each string and value in the JSON object... wprintf (L"String:%s", str.as_string ());    wprintf (L"Value:%s", v.to_string ());  }  return 0;}

Details: The C ++ rest SDK ("Casablanca ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.