{"id":1640,"date":"2013-08-19T18:16:38","date_gmt":"2013-08-19T16:16:38","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=1640"},"modified":"2017-11-20T01:31:38","modified_gmt":"2017-11-19T23:31:38","slug":"full-fledged-client-server-example-with-cpprest-sdk-110","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/","title":{"rendered":"Full-fledged client-server example with C++ REST SDK 1.1.0"},"content":{"rendered":"<p class=\"edit\"><strong>UPDATE<\/strong>: for an updated version of this demo, using C++ REST SDK 2.10 see this <a href=\"http:\/\/mariusbancila.ro\/blog\/2017\/11\/19\/revisited-full-fledged-client-server-example-with-c-rest-sdk-2-10\/\">blog post<\/a>.<\/p>\n<p>In my <a href=\"http:\/\/mariusbancila.ro\/blog\/2013\/08\/02\/cpp-rest-sdk-in-visual-studio-2013\/\">previous post<\/a> I shown how you can build a C++ application with the <a href=\"https:\/\/casablanca.codeplex.com\">C++ REST<\/a> SDK that fetches search results from a search engine. In this post, I will go a step further and develop a client-server application from scratch using version 1.1.0 of the SDK. This version features an <a href=\"https:\/\/casablanca.codeplex.com\/wikipage?title=HTTP%20Listener&amp;referringTitle=Documentation\">HTTP listener<\/a> implementation (still in an experimental phase). Notice that for the time being this 1.1.0 SDK release does not work with Visual Studio 2013 Preview. This samples are built with Visual Studio 2012.<\/p>\n<h2>Overview of the problem to solve<\/h2>\n<p>The server manages a dictionary of key-value pairs (both strings) and supports several HTTP request methods:<\/p>\n<ul>\n<li><strong>GET<\/strong>: retrieves all the key-value pair from the dictionary.<br \/>\nThe response is a JSON object representing key-value pairs (eg. <tt>{\"one\" : \"100\", \"two\" : \"200\"}<\/tt>).<\/li>\n<li><strong>POST<\/strong>: retrieves the values of the specified keys from the dictionary.<br \/>\nThe request is a JSON array of strings (eg. <tt>[\"one\", \"two\", \"three\"]<\/tt>).<br \/>\nThe response is similar to the GET method, except that only requested keys are returned.<\/li>\n<li><strong>PUT<\/strong>: inserts new pairs of key-values in the dictionary. If a key is already found its value is updated.<br \/>\nThe request is a JSON object representing pairs of keys and values (eg. <tt>{\"one\" : \"100\", \"two\" : \"200\"}<\/tt>)<br \/>\nThe response is a JSON object representing they key and the result for the action, such as addition or update (eg. <tt>{\"one\" : \"&lt;put&gt;\", \"two\" : \"&lt;updated&gt;\"}<\/tt>).<\/li>\n<li><strong>DEL<\/strong>: deletes the specified keys from the dictionary.<br \/>\nThe request is a JSON array of strings (eg. <tt>[\"one\", \"two\", \"three\"]<\/tt>).<br \/>\nThe response is a JSON object representing they key and the result for the action, such as success or failure (eg. <tt>{\"one\" : \"&lt;deleted&gt;\", \"two\" : \"&lt;failed&gt;\"}<\/tt>).<\/li>\n<\/ul>\n<p>Notice that the server implements both <tt>GET<\/tt> and <tt>POST<\/tt>. The <tt>GET<\/tt> method is supposed to request a representation of the specified URI. Though it is theoretically possible that a <tt>GET<\/tt> request carries a body, in practice that should be ignored. The C++ REST library actually triggers an exception if you make a <tt>GET<\/tt> request with a body. Therefore, <tt>GET<\/tt> is used to return the entire content of the dictionary and the <tt>POST<\/tt> method, that supports a body, returns only the requested key-value pairs.<\/p>\n<p>The client can make HTTP requests to the server, adding or updating key-values, fetch or delete existing pairs.<\/p>\n<p>All communication, both for the request and the answer, is done using JSON values.<\/p>\n<h2>The server implementation<\/h2>\n<p>On the server side we have to do the following:<\/p>\n<ul>\n<li>instantiate an <tt>http_listener<\/tt> object, specifying the URI where it should listen for requests.<\/li>\n<li>provide handlers for the HTTP request methods for the listener.<\/li>\n<li>open the listener and loop to wait for messages.<\/li>\n<\/ul>\n<p>The core of the server application is shown below (except for the request handlers).<\/p>\n<pre class=\"brush:cpp\">\r\n#include &lt;cpprest\/http_listener.h&gt;\r\n#include &lt;cpprest\/json.h&gt;\r\n#pragma comment(lib, \"cpprest110_1_1\")\r\n\r\nusing namespace web;\r\nusing namespace web::http;\r\nusing namespace web::http::experimental::listener;\r\n\r\n#include &lt;iostream&gt;\r\n#include &lt;map&gt;\r\n#include &lt;set&gt;\r\n#include &lt;string&gt;\r\nusing namespace std;\r\n\r\n#define TRACE(msg)            wcout &lt;&lt; msg\r\n#define TRACE_ACTION(a, k, v) wcout &lt;&lt; a &lt;&lt; L\" (\" &lt;&lt; k &lt;&lt; L\", \" &lt;&lt; v &lt;&lt; L\")\\n\"\r\n\r\nmap<utility::string_t, utility::string_t> dictionary;\r\n\r\n\/* handlers implementation *\/\r\n\r\nint main()\r\n{\r\n   http_listener listener(L\"http:\/\/localhost\/restdemo\");\r\n\r\n   listener.support(methods::GET, handle_get);\r\n   listener.support(methods::POST, handle_post);\r\n   listener.support(methods::PUT, handle_put);\r\n   listener.support(methods::DEL, handle_del);\r\n\r\n   try\r\n   {\r\n      listener\r\n         .open()\r\n         .then([&listener](){TRACE(L\"\\nstarting to listen\\n\");})\r\n         .wait();\r\n\r\n      while (true);\r\n   }\r\n   catch (exception const &amp; e)\r\n   {\r\n      wcout &lt;&lt; e.what() &lt;&lt; endl;\r\n   }\r\n\r\n   return 0;\r\n}\r\n<\/pre>\n<p>In this simple implementation the dictionary is a <tt>std::map<\/tt>. Its content is not persisted to disk, it is reloaded each time the server starts.<\/p>\n<p>Let&#8217;s now look at the handlers. As mentioned earlier the <tt>GET<\/tt> method is a bit different than the others. A <tt>GET<\/tt> request should return all the key-value pairs in the server&#8217;s dictionary. Its implementation looks like this:<\/p>\n<pre class=\"brush:cpp\">\r\nvoid handle_get(http_request request)\r\n{\r\n   TRACE(L\"\\nhandle GET\\n\");\r\n\r\n   json::value::field_map answer;\r\n\r\n   for(auto const &amp; p : dictionary)\r\n   {\r\n      answer.push_back(make_pair(json::value(p.first), json::value(p.second)));\r\n   }\r\n\r\n   request.reply(status_codes::OK, json::value::object(answer));\r\n}\r\n<\/pre>\n<p>What it does is iterating through the dictionary and putting its key-value pairs into a <tt>json::value::field_map<\/tt>. That object is then sent back the the client.<\/p>\n<p>The <tt>POST<\/tt>, <tt>PUT<\/tt> and <tt>DEL<\/tt> methods are a bit more complicated, because they all receive a JSON value specifying either keys to fetch or delete or pairs of key-value to add or update in the dictionary. Since some code would get duplicated several times I have created a generic method for handling requests that takes a function that evaluates the JSON request value and builds the response JSON value.<\/p>\n<pre class=\"brush:cpp\">\r\nvoid handle_request(http_request request, \r\n                    function&lt;void(json::value &amp;, json::value::field_map &amp;)&gt; action)\r\n{\r\n   json::value::field_map answer;\r\n\r\n   request\r\n      .extract_json()\r\n      .then([&amp;answer, &amp;action](pplx::task&lt;json::value&gt; task) {\r\n         try\r\n         {\r\n            auto &amp; jvalue = task.get();\r\n\r\n            if (!jvalue.is_null())\r\n            {\r\n               action(jvalue, answer);\r\n            }\r\n         }\r\n         catch (http_exception const &amp; e)\r\n         {\r\n            wcout &lt;&lt; e.what() &lt;&lt; endl;\r\n         }\r\n      })\r\n      .wait();\r\n\r\n   request.reply(status_codes::OK, json::value::object(answer));\r\n}\r\n<\/pre>\n<p>The handlers for <tt>POST<\/tt>, <tt>PUT<\/tt> and <tt>DEL<\/tt> will then call this generic method providing a lambda with the actual core implementation of each request handling.<\/p>\n<pre class=\"brush:cpp\">\r\nvoid handle_post(http_request request)\r\n{\r\n   TRACE(\"\\nhandle POST\\n\");\r\n\r\n   handle_request(\r\n      request, \r\n      [](json::value &amp; jvalue, json::value::field_map &amp; answer)\r\n      {\r\n         for (auto const &amp; e : jvalue)\r\n         {\r\n            if (e.second.is_string())\r\n            {\r\n               auto key = e.second.as_string();\r\n\r\n               auto pos = dictionary.find(key);\r\n               if (pos == dictionary.end())\r\n               {\r\n                  answer.push_back(make_pair(json::value(key), json::value(L\"&lt;nil&gt;\")));\r\n               }\r\n               else\r\n               {\r\n                  answer.push_back(make_pair(json::value(pos->first), json::value(pos->second)));\r\n               }\r\n            }\r\n         }\r\n      }\r\n   );\r\n}\r\n\r\nvoid handle_put(http_request request)\r\n{\r\n   TRACE(\"\\nhandle PUT\\n\");\r\n\r\n   handle_request(\r\n      request,\r\n      [](json::value &amp; jvalue, json::value::field_map &amp; answer)\r\n      {\r\n         for (auto const &amp; e : jvalue)\r\n         {\r\n            if (e.first.is_string() &amp;&amp; e.second.is_string())\r\n            {\r\n               auto key = e.first.as_string();\r\n               auto value = e.second.as_string();\r\n\r\n               if (dictionary.find(key) == dictionary.end())\r\n               {\r\n                  TRACE_ACTION(L\"added\", key, value);\r\n                  answer.push_back(make_pair(json::value(key), json::value(L\"&lt;put&gt;\")));\r\n               }\r\n               else\r\n               {\r\n                  TRACE_ACTION(L\"updated\", key, value);\r\n                  answer.push_back(make_pair(json::value(key), json::value(L\"&lt;updated&gt;\")));\r\n               }\r\n\r\n               dictionary[key] = value;\r\n            }\r\n         }\r\n      }\r\n   );\r\n}\r\n\r\nvoid handle_del(http_request request)\r\n{\r\n   TRACE(\"\\nhandle DEL\\n\");\r\n\r\n   handle_request(\r\n      request,\r\n      [](json::value &amp; jvalue, json::value::field_map &amp; answer)\r\n      {\r\n         set&lt;utility::string_t&gt; keys;\r\n         for (auto const &amp; e : jvalue)\r\n         {\r\n            if (e.second.is_string())\r\n            {\r\n               auto key = e.second.as_string();\r\n\r\n               auto pos = dictionary.find(key);\r\n               if (pos == dictionary.end())\r\n               {\r\n                  answer.push_back(make_pair(json::value(key), json::value(L\"&lt;failed&gt;\")));\r\n               }\r\n               else\r\n               {\r\n                  TRACE_ACTION(L\"deleted\", pos->first, pos->second);\r\n                  answer.push_back(make_pair(json::value(key), json::value(L\"&lt;deleted&gt;\")));\r\n                  keys.insert(key);\r\n               }\r\n            }\r\n         }\r\n\r\n         for (auto const &amp; key : keys)\r\n            dictionary.erase(key);\r\n      }\r\n   );\r\n}\r\n<\/pre>\n<p>And that is all with the server.<\/p>\n<h2>The client implementation<\/h2>\n<p>On the client side we need a <tt>http_client<\/tt> object to make HTTP requests to the server. It has an overloaded method <tt>request()<\/tt> that allows specifying the request method, a path and a JSON value for instance. A JSON value is not sent if the method is <tt>GET<\/tt> (or <tt>HEAD<\/tt>). Since for each request the answer is a JSON value, I have created a method called <tt>make_request()<\/tt> that dispatches the request and when the response arrives it fetches the JSON value and displays it in the console.<\/p>\n<p>The core of the client code looks like this:<\/p>\n<pre class=\"brush:cpp\">\r\n#include &lt;cpprest\/http_client.h&gt;\r\n#include &lt;cpprest\/json.h&gt;\r\n#pragma comment(lib, \"cpprest110_1_1\")\r\n\r\nusing namespace web;\r\nusing namespace web::http;\r\nusing namespace web::http::client;\r\n\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nvoid display_field_map_json(json::value &amp; jvalue)\r\n{\r\n   if (!jvalue.is_null())\r\n   {\r\n      for (auto const &amp; e : jvalue)\r\n      {\r\n         wcout &lt;&lt; e.first.as_string() &lt;&lt; L\" : \" &lt;&lt; e.second.as_string() &lt;&lt; endl;\r\n      }\r\n   }\r\n}\r\n\r\npplx::task&lt;http_response&gt; make_task_request(http_client &amp; client, \r\n                                            method mtd, \r\n                                            json::value const &amp; jvalue)\r\n{\r\n   return (mtd == methods::GET || mtd == methods::HEAD) ? \r\n      client.request(mtd, L\"\/restdemo\") : \r\n      client.request(mtd, L\"\/restdemo\", jvalue);\r\n}\r\n\r\nvoid make_request(http_client &amp; client, method mtd, json::value const &amp; jvalue)\r\n{\r\n   make_task_request(client, mtd, jvalue)\r\n      .then([](http_response response)\r\n      {\r\n         if (response.status_code() == status_codes::OK)\r\n         {\r\n            return response.extract_json();\r\n         }\r\n         return pplx::task_from_result(json::value());\r\n      })\r\n      .then([](pplx::task&lt;json::value&gt; previousTask)\r\n      {\r\n         try\r\n         {\r\n            display_field_map_json(previousTask.get());\r\n         }\r\n         catch (http_exception const &amp; e)\r\n         {\r\n            wcout &lt;&lt; e.what() &lt;&lt; endl;\r\n         }\r\n      })\r\n      .wait();\r\n}\r\n<\/pre>\n<p>In the <tt>main()<\/tt> function I then just make a series of requests to the server, putting, fetching and deleting key-values from the server&#8217;s dictionary.<\/p>\n<pre class=\"brush:cpp\">\r\nint main()\r\n{\r\n   http_client client(U(\"http:\/\/localhost\"));\r\n\r\n   json::value::field_map putvalue;\r\n   putvalue.push_back(make_pair(json::value(L\"one\"), json::value(L\"100\")));\r\n   putvalue.push_back(make_pair(json::value(L\"two\"), json::value(L\"200\")));\r\n\r\n   wcout &lt;&lt; L\"\\nput values\\n\";\r\n   make_request(client, methods::PUT, json::value::object(putvalue));\r\n\r\n   auto getvalue = json::value::array();\r\n   getvalue[0] = json::value(L\"one\");\r\n   getvalue[1] = json::value(L\"two\");\r\n   getvalue[2] = json::value(L\"three\");\r\n\r\n   wcout &lt;&lt; L\"\\nget values (POST)\\n\";\r\n   make_request(client, methods::POST, getvalue);\r\n\r\n   auto delvalue = json::value::array();\r\n   delvalue[0] = json::value(L\"one\");\r\n\r\n   wcout &lt;&lt; L\"\\ndelete values\\n\";\r\n   make_request(client, methods::DEL, delvalue);\r\n\r\n   wcout &lt;&lt; L\"\\nget values (POST)\\n\";\r\n   make_request(client, methods::POST, getvalue);\r\n\r\n   wcout &lt;&lt; L\"\\nget values (GET)\\n\";\r\n   make_request(client, methods::GET, json::value::null());\r\n\r\n   return 0;\r\n}\r\n<\/pre>\n<h2>The client and server in action<\/h2>\n<p>You need to start the server first and then run the client. The output from running the client is:<\/p>\n<pre class=\"console\">\r\nput values\r\none : &lt;put&gt;\r\ntwo : &lt;put&gt;\r\n\r\nget values (POST)\r\none : 100\r\ntwo : 200\r\nthree : &lt;nil&gt;\r\n\r\ndelete values\r\none : &lt;deleted&gt;\r\n\r\nget values (POST)\r\none : &lt;nil&gt;\r\ntwo : 200\r\nthree : &lt;nil&gt;\r\n\r\nget values (GET)\r\ntwo : 200\r\n<\/pre>\n<p>On the server console the output is:<\/p>\n<pre class=\"console\">\r\nstarting to listen\r\n\r\nhandle PUT\r\nadded (one, 100)\r\nadded (two, 200)\r\n\r\nhandle POST\r\n\r\nhandle DEL\r\ndeleted (one, 100)\r\n\r\nhandle POST\r\n\r\nhandle GET\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>UPDATE: for an updated version of this demo, using C++ REST SDK 2.10 see this blog post. In my previous post I shown how you can build a C++ application with the C++ REST SDK that fetches search results from a search engine. In this post, I will go a step further and develop a &#8230; <a title=\"Full-fledged client-server example with C++ REST SDK 1.1.0\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/\" aria-label=\"Read more about Full-fledged client-server example with C++ REST SDK 1.1.0\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,19],"tags":[451,368,380,378,379,381,317],"class_list":["post-1640","post","type-post","status-publish","format-standard","hentry","category-c","category-web","tag-c","tag-casablanca","tag-client","tag-cpprest","tag-restful","tag-server","tag-vs2012"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"See how to implement a client-server application using C++ REST SDK 1.1.0\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,cpprest,casablanca,restful,client,server,vs2012\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Full-fledged client-server example with C++ REST 1.1.0\" \/>\n\t\t<meta property=\"og:description\" content=\"See how to implement a client-server application using C++ REST SDK 1.1.0\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2013-08-19T16:16:38+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2017-11-19T23:31:38+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Full-fledged client-server example with C++ REST 1.1.0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"See how to implement a client-server application using C++ REST SDK 1.1.0\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#article\",\"name\":\"Full-fledged client-server example with C++ REST 1.1.0\",\"headline\":\"Full-fledged client-server example with C++ REST SDK 1.1.0\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2013-08-19T18:16:38+02:00\",\"dateModified\":\"2017-11-20T01:31:38+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":34,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#webpage\"},\"articleSection\":\"C++, Web, C++, casablanca, client, cpprest, restful, server, VS2012\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#listItem\",\"name\":\"Full-fledged client-server example with C++ REST SDK 1.1.0\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#listItem\",\"position\":5,\"name\":\"Full-fledged client-server example with C++ REST SDK 1.1.0\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/\",\"name\":\"Full-fledged client-server example with C++ REST 1.1.0\",\"description\":\"See how to implement a client-server application using C++ REST SDK 1.1.0\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2013\\\/08\\\/19\\\/full-fledged-client-server-example-with-cpprest-sdk-110\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2013-08-19T18:16:38+02:00\",\"dateModified\":\"2017-11-20T01:31:38+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Full-fledged client-server example with C++ REST 1.1.0","description":"See how to implement a client-server application using C++ REST SDK 1.1.0","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/","robots":"max-image-preview:large","keywords":"c++,cpprest,casablanca,restful,client,server,vs2012","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#article","name":"Full-fledged client-server example with C++ REST 1.1.0","headline":"Full-fledged client-server example with C++ REST SDK 1.1.0","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2013-08-19T18:16:38+02:00","dateModified":"2017-11-20T01:31:38+02:00","inLanguage":"en-US","commentCount":34,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#webpage"},"articleSection":"C++, Web, C++, casablanca, client, cpprest, restful, server, VS2012"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#listItem","name":"Full-fledged client-server example with C++ REST SDK 1.1.0"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#listItem","position":5,"name":"Full-fledged client-server example with C++ REST SDK 1.1.0","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/","name":"Full-fledged client-server example with C++ REST 1.1.0","description":"See how to implement a client-server application using C++ REST SDK 1.1.0","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2013-08-19T18:16:38+02:00","dateModified":"2017-11-20T01:31:38+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Full-fledged client-server example with C++ REST 1.1.0","og:description":"See how to implement a client-server application using C++ REST SDK 1.1.0","og:url":"https:\/\/mariusbancila.ro\/blog\/2013\/08\/19\/full-fledged-client-server-example-with-cpprest-sdk-110\/","article:published_time":"2013-08-19T16:16:38+00:00","article:modified_time":"2017-11-19T23:31:38+00:00","twitter:card":"summary","twitter:title":"Full-fledged client-server example with C++ REST 1.1.0","twitter:description":"See how to implement a client-server application using C++ REST SDK 1.1.0"},"aioseo_meta_data":{"post_id":"1640","title":"Full-fledged client-server example with C++ REST 1.1.0","description":"See how to implement a client-server application using C++ REST SDK 1.1.0","keywords":[{"label":"c++","value":"c++"},{"label":"cpprest","value":"cpprest"},{"label":"casablanca","value":"casablanca"},{"label":"restful","value":"restful"},{"label":"client","value":"client"},{"label":"server","value":"server"},{"label":"vs2012","value":"vs2012"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:12:20","updated":"2025-12-12 07:40:13","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":34,"uagb_excerpt":"UPDATE: for an updated version of this demo, using C++ REST SDK 2.10 see this blog post. In my previous post I shown how you can build a C++ application with the C++ REST SDK that fetches search results from a search engine. In this post, I will go a step further and develop a&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">Web<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">Web<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">casablanca<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">client<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">cpprest<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">restful<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">server<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">VS2012<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">casablanca<\/span>","<span class=\"advgb-post-tax-term\">client<\/span>","<span class=\"advgb-post-tax-term\">cpprest<\/span>","<span class=\"advgb-post-tax-term\">restful<\/span>","<span class=\"advgb-post-tax-term\">server<\/span>","<span class=\"advgb-post-tax-term\">VS2012<\/span>"]}},"comment_count":"34","relative_dates":{"created":"Posted 13 years ago","modified":"Updated 9 years ago"},"absolute_dates":{"created":"Posted on August 19, 2013","modified":"Updated on November 20, 2017"},"absolute_dates_time":{"created":"Posted on August 19, 2013 6:16 pm","modified":"Updated on November 20, 2017 1:31 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-qs","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=1640"}],"version-history":[{"count":23,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1640\/revisions"}],"predecessor-version":[{"id":2634,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1640\/revisions\/2634"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=1640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=1640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=1640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}