微軟開源 C++ REST SDK

jopen 11年前發布 | 34K 次閱讀 C/C++開發 C/C++

  微軟近日開源了C++ REST SDK,托管在自己的 CodePlex 平臺上。 

  項目地址:http://casablanca.codeplex.com 

  C++ REST SDK 包含在 Casablanca 項目中。 Casablanca 是一個 C++ 本地庫,旨在幫助開發者的 C++ 應用程序訪問云服務。如果你想編寫一個響應式的 C++ 客戶端應用程序,或者是一個可擴展的服務端解決方案,可以試試 Casablanca。除了C++ REST SDK 外,Casablanca 項目還包含 Azure SDK for C++。 

  C++ REST SDK 中包含了一些工具,可以幫助開發者快速編寫現代、異步、可連接 REST 服務的 C++ 應用程序,遵循C++11 標準,目前支持 Windows 7、Windows 8(包括 Windows Store 和桌面應用)和 Linux。 

  該 SDK 的主要特性包括: 

  • 能夠通過 HTTP Client 創建服務器連接,并發送請求、處理響應
  • 支持構造和使用 URI(Uniform Resource Identifiers,統一資源標識符)
  • 構造、解析和序列化 JSON 值
  • 通過 Streams 和 Stream Buffers 從底層介質異步讀取/寫入字節

  下面的示例演示了如何上傳文件到 HTTP 服務器:

#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;
}

  下面的示例演示了如何構建并遍歷 JSON 值:

#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;
}

  詳細信息:The C++ REST SDK ("Casablanca")

來自: www.iteye.com
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!