每日科技英文52: 微軟的The C++ REST SDK 庫(有源碼)

一直想要一個跨平臺的嘁扼,C++版的糟秘,基于異步IO的,具有REST風(fēng)格的束铭,可以支持websock 的service庫廓块。

貌似微軟的CPPRestSDK能夠滿足需求!因此與大家共享契沫。

1. CPPRestSDK簡介:

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

2. 特點:

  • Features - HTTP client/server, JSON, URI, asynchronous streams, WebSockets client, oAuth
  • PPL Tasks - A powerful model for composing asynchronous operations based on C++ 11 features
  • Platforms - Windows desktop, Windows Store (UWP), Linux, OS X, Unix, iOS, and Android
  • Support for Visual Studio 2015 and 2017 with debugger visualizers

3. FAQ:

  • What is C++ Rest SDK and why should I care about it?

C++ Rest SDK is your toolbox for accessing connected applications using modern C++ features and best practices.

Historically C++ developers have been lacking a basic set of tools that enable them to access and author REST services in a productive, scalable and asynchronous manner. C++ Rest SDK aims to alleviate some of the pain felt by developers by providing a cross-platform library that is modeled on simplicity, extensibility and composition.

  • C++ Rest SDK uses tasks in many of the APIs. What are tasks?

The tasks library shipping with C++ Rest SDK is a port of the PPL tasks library that’s available with Visual C++ in Visual Studio 2012. In order to make it work alongside the existing PPL library, we changed the namespace to “pplx” in the ported library.

Tasks are emerging as the fundamental mechanism to compose asynchronous operations across a variety of APIs and runtime environments. C++ developers writing code for Windows 8 with Visual Studio 2012 can use them, .NET has had them for a while and increasing their use in .NET 4.5, and JavaScript provides the same concept in its promises pattern.

  • Asynchrony is mentioned a lot in casablanca. Why should I care?

Asynchrony is about efficiency and responsiveness. If you are writing a graphical user interface client, you want to use an asynchronous operation whenever there is a chance of it taking more than a few milliseconds to execute, or the UI will be jerky and possibly freeze. PPL tasks make it really easy to write this kind of code.

If you are writing server-side code, you are likely doing a lot of I/O: reading files, logging data, using network resources, accessing databases. These activities all involve waiting for potentially long-running operations, and asynchrony helps your code wait efficiently. You are likely to want your services to scale to serve many simultaneous client requests, which can be challenging when using blocking (synchronous) APIs, since each waiting operation holds on to its thread while waiting. Threads are very expensive resources.

  • Can I use C++ Rest SDK on iOS, Linux, Android, or other platforms?

The API surface of C++ Rest SDK is platform-agnostic, and it had already supports many platforms including iOS and Android.

  • What is utility::string_t and the 'U' macro?

The C++ REST SDK uses a different string type dependent on the platform being targeted. For example for the Windows platforms utility::string_t is std::wstring using UTF-16, on Linux std::string using UTF-8. The 'U' macro can be used to create a string literal of the platform type. If you are using a library causing conflicts with the 'U' macro, for example Boost.Iostreams it can be turned off by defining the macro '_TURN_OFF_PLATFORM_STRING' before including the C++ REST SDK header files.

  • You have a JSON library but not an XML library. What’s up with that?

Two things influenced this decision:

For many developers of REST services, JSON is the preferred format for exchanging text-serialized data. It’s simpler than XML and it easier to read. Given this preference, we thought it important to prioritize JSON over XML.
There are already several good native XML libraries for both Windows and Linux. For example, on Windows, we’re using XmlLite internally in the C++ Rest SDK libraries in a couple of places. That library has a lot of Win32 “jargon” to it, and we may eventually wrap it in something that is thin but looks like standard C++, but XmlLite is a very functional library and has excellent performance. There are also open-source solutions available.

  • C++ Rest SDK supports accessing REST services. Why not SOAP?

To do a good job at supporting SOAP services, you need more tooling than what we could get into this release. If you do need to access SOAP services from native code, there’s Windows Web Services. We may add SOAP as a C++ Rest SDK scenario in the future, so please give us feedback on this if it’s important to you.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末带猴,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子懈万,更是在濱河造成了極大的恐慌拴清,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件会通,死亡現(xiàn)場離奇詭異口予,居然都是意外死亡,警方通過查閱死者的電腦和手機涕侈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進店門沪停,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事木张≈诒妫” “怎么了?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵舷礼,是天一觀的道長鹃彻。 經(jīng)常有香客問我,道長妻献,這世上最難降的妖魔是什么蛛株? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮育拨,結(jié)果婚禮上谨履,老公的妹妹穿的比我還像新娘。我一直安慰自己熬丧,他們只是感情好屉符,可當(dāng)我...
    茶點故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著锹引,像睡著了一般矗钟。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上嫌变,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天吨艇,我揣著相機與錄音,去河邊找鬼腾啥。 笑死东涡,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的倘待。 我是一名探鬼主播疮跑,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼凸舵!你這毒婦竟也來了祖娘?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤啊奄,失蹤者是張志新(化名)和其女友劉穎渐苏,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體菇夸,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡琼富,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了庄新。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鞠眉。...
    茶點故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡薯鼠,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出械蹋,到底是詐尸還是另有隱情人断,我是刑警寧澤,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布朝蜘,位于F島的核電站,受9級特大地震影響涩金,放射性物質(zhì)發(fā)生泄漏谱醇。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一步做、第九天 我趴在偏房一處隱蔽的房頂上張望副渴。 院中可真熱鬧,春花似錦全度、人聲如沸煮剧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽勉盅。三九已至,卻和暖如春顶掉,著一層夾襖步出監(jiān)牢的瞬間草娜,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工痒筒, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留宰闰,地道東北人。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓簿透,卻偏偏與公主長得像移袍,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子老充,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,876評論 2 361