Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Casablanca でHTTP 
H.26/09/20 
Egtra 
For Boost.勉強会#16
自分 
•Egtra 
–Twitter: @egtra 
–http://dev.activebasic.com/egtra/ 
•仕事: 主にVisual C++ 2005 (Windows) 
–最近C++ (Linux)も少し
動機:私は探していた 
•HTTPライブラリ(クライアント) 
–主にAPIサーバー相手の通信 
•クロスプラットフォーム 
–WindowsとLinuxほかUnix系
C++ REST SDK 
•クライアント・サーバ 
–HTTPS対応 
•JSON, Oauth, WebScoket 
•Win/Mac/Linuxなど 
•C++11必須 
•MS発OSSライブラリ 
•https://casablanc...
プラットフォーム 
•Windows 
–Desktop/Store/Phone 
•Linux, FreeBSD 
–Android: 対応中(?) 
•Mac OS X, iOS
こんな感じ(1⁄2) 
http_clientclient(U("http://example.com/")); 
http_requestreq(methods::POST); 
req.set_request_uri(U("my_api.t...
こんな感じ(2⁄2) 
autobodyTask= 
resTask.then([](consthttp_response& res) { 
// res.status_code(); 
// res.headers().content_typ...
こんな感じ(まとめ) 
•http_clientを作る 
•requestに↑ を渡す 
•http_responseを受け取る 
•extract_*()で中身を得る
pplx::task 
•VC++のppl::taskの移植版 
•ほぼstd::future 
–thenメンバ関数がある! 
–協調的キャンセル機構など
thenによるチェイン(1) 
client.request(req) 
.then([](constauto& res) { 
returnres.extract_vector(); 
}).then([](constauto& vec) {...
thenによるチェイン(2) 
pplx::task<std::string> call_my_api() { 
returnclient.request(req) 
.then([](constauto& res) { 
returnres....
ヘッダー 
•req.headers().… orres.headers().… 
–add(name, value), remove(name) 
–has(name), [], find(name) 
–begin(), end(), si...
リクエスト・ボディー 
•req.set_body(……) 
–文字列(std::string orstring_t) 
–文字列, Content-Type文字列 
–json::value 
–std::vector<unsigned ch...
ステータスコード 
•res.status_code() -> status_code 
–typedefunsigned shortstatus_code; 
–定数status_codes::OKほか 
•res.reason_phrase...
レスポンス・ボディー 
•res.extract_string()-> pplx::task<文字列> 
•res.extract_json() -> pplx::<json::value> 
•res.extract_vector() -> ...
文字列 
•Windows: UTF-16(wchar_t) 
•その他: UTF-8(char) 
•共通化 
–char_t, string_t, stringstream_t 
–U("リテラル") 
–ucout, ucin, ucerr
足回り 
•Windows: 
–WinHTTP.dll, WinHTTP.sys 
–IXmlHttpRequest2 
•その他: Boost.Asio 
–SSL: boost::asio::ssl(OpenSSL)
インストール 
•Windows: 
–Visual Studio内nuget
インストール(Ubuntu) 
apt-get install openssl-devcmake 
cdcasablanca/Release 
mkdirbuild.release 
cdbuild.release 
cmake.. BOOST...
This work is licensed under a Creative Commons Attribution- ShareAlike4.0 International License.
Upcoming SlideShare
Loading in …5
×

Casablanca

2,406 views

Published on

Boost.勉強会#16 大阪で発表したときのものです。

Published in: Technology
  • ..............ACCESS that WEBSITE Over for All Ebooks ................ ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Casablanca

  1. 1. Casablanca でHTTP H.26/09/20 Egtra For Boost.勉強会#16
  2. 2. 自分 •Egtra –Twitter: @egtra –http://dev.activebasic.com/egtra/ •仕事: 主にVisual C++ 2005 (Windows) –最近C++ (Linux)も少し
  3. 3. 動機:私は探していた •HTTPライブラリ(クライアント) –主にAPIサーバー相手の通信 •クロスプラットフォーム –WindowsとLinuxほかUnix系
  4. 4. C++ REST SDK •クライアント・サーバ –HTTPS対応 •JSON, Oauth, WebScoket •Win/Mac/Linuxなど •C++11必須 •MS発OSSライブラリ •https://casablanca.codeprex.com/ ※ グレーは今回私が使っていないものです。
  5. 5. プラットフォーム •Windows –Desktop/Store/Phone •Linux, FreeBSD –Android: 対応中(?) •Mac OS X, iOS
  6. 6. こんな感じ(1⁄2) http_clientclient(U("http://example.com/")); http_requestreq(methods::POST); req.set_request_uri(U("my_api.txt")); req.set_body(……); autoresTask= client.request(req); // resTaskはpplx::task<http_response>
  7. 7. こんな感じ(2⁄2) autobodyTask= resTask.then([](consthttp_response& res) { // res.status_code(); // res.headers().content_type(); returnres.extract_body(); }; std::vector<unsigned char> body = bodyTask.get();
  8. 8. こんな感じ(まとめ) •http_clientを作る •requestに↑ を渡す •http_responseを受け取る •extract_*()で中身を得る
  9. 9. pplx::task •VC++のppl::taskの移植版 •ほぼstd::future –thenメンバ関数がある! –協調的キャンセル機構など
  10. 10. thenによるチェイン(1) client.request(req) .then([](constauto& res) { returnres.extract_vector(); }).then([](constauto& vec) { returnvecをいい感じに解析; }).then([](conststd::string& result) { ……
  11. 11. thenによるチェイン(2) pplx::task<std::string> call_my_api() { returnclient.request(req) .then([](constauto& res) { returnres.extract_vector(); }).then([](constauto& vec) { returnvecをいい感じに解析; }); }
  12. 12. ヘッダー •req.headers().… orres.headers().… –add(name, value), remove(name) –has(name), [], find(name) –begin(), end(), size(), empty() –content_type(), content_length(), –date(), cache_control()(読み取り) •set_…(value)(書き込み)
  13. 13. リクエスト・ボディー •req.set_body(……) –文字列(std::string orstring_t) –文字列, Content-Type文字列 –json::value –std::vector<unsigned char> –concurrency::stream::istream
  14. 14. ステータスコード •res.status_code() -> status_code –typedefunsigned shortstatus_code; –定数status_codes::OKほか •res.reason_phrase()
  15. 15. レスポンス・ボディー •res.extract_string()-> pplx::task<文字列> •res.extract_json() -> pplx::<json::value> •res.extract_vector() -> pplx::task<std::vector<unsigned char>> •body() -> concurrency::streams::istream
  16. 16. 文字列 •Windows: UTF-16(wchar_t) •その他: UTF-8(char) •共通化 –char_t, string_t, stringstream_t –U("リテラル") –ucout, ucin, ucerr
  17. 17. 足回り •Windows: –WinHTTP.dll, WinHTTP.sys –IXmlHttpRequest2 •その他: Boost.Asio –SSL: boost::asio::ssl(OpenSSL)
  18. 18. インストール •Windows: –Visual Studio内nuget
  19. 19. インストール(Ubuntu) apt-get install openssl-devcmake cdcasablanca/Release mkdirbuild.release cdbuild.release cmake.. BOOST_ROOT=…… # aptでBoostを入れたなら、BOOST_ROOT不要
  20. 20. This work is licensed under a Creative Commons Attribution- ShareAlike4.0 International License.

×