Table of Contents
C++ REST SDK - cpprestsdk 已经基本停止维护(微软不再主推)
C++ REST SDK(代码名称“Casablanca”)
https://github.com/Microsoft/cpprestsdk
提供现代的跨平台异步 API,用于与 REST 服务进行交互。
对任何 HTTP 服务器执行 REST 调用,内置有对 JSON 文档分析和序列化的支持
支持 OAuth 1 和 2,包括本地重定向侦听器
使 Websocket 连接到远程服务
基于 PPL 的完全异步任务 API,包含内置线程池
支持 Windows 桌面 (7+)、Windows Server (2012+)、通用 Windows 平台、Linux、OSX、Android 和 iOS。
Microsoft Cpp Rest SDK源码编译与建立HTTP服务器例子
https://www.jianshu.com/p/1ecdab88b8bf
Sample code of cpprestsdk (casablanca), it's a sample example for beginner to get started with cpprestsdk with database(currently PostgreSQL) integration with basic structure, programmer can extend it.
https://github.com/Meenapintu/Restweb
cpp-httplib库
C++使用 cpp-httplib库发布一个web api服务器
使用 cpp-httplib 作为 HTTP 服务器库
nlohmann/json(超轻量)
HTTP:libcurl(工业标准)
examples
json body = {
{"ak", "xxx"},
{"cmd", "GetWorkState"}
};
std::string bodyStr = body.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://api.xxx.com");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, bodyStr.c_str());
// header
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
其他可选库
C++ REST SDK(代码名称“Casablanca”)
https://docs.microsoft.com/zh-cn/cpp/cloud/cloud-and-web-programming-in-visual-cpp?view=vs-2019
