微软开源 C++ REST SDK

jopen 11年前

  微软近日开源了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