From 43b8d21419d548a1054b435f37708dcf6149ee8d Mon Sep 17 00:00:00 2001 From: Juraj Michalek Date: Sun, 24 Nov 2013 15:54:44 +0100 Subject: [PATCH] add rest-client example --- README.md | 16 ++++ rest/rest-client/rest-client.sln | 22 +++++ rest/rest-client/rest-client/ReadMe.txt | 7 ++ rest/rest-client/rest-client/packages.config | 5 + rest/rest-client/rest-client/rest-client.cpp | 43 +++++++++ .../rest-client/rest-client.vcxproj | 92 +++++++++++++++++++ .../rest-client/rest-client.vcxproj.filters | 28 ++++++ 7 files changed, 213 insertions(+) create mode 100644 rest/rest-client/rest-client.sln create mode 100644 rest/rest-client/rest-client/ReadMe.txt create mode 100644 rest/rest-client/rest-client/packages.config create mode 100644 rest/rest-client/rest-client/rest-client.cpp create mode 100644 rest/rest-client/rest-client/rest-client.vcxproj create mode 100644 rest/rest-client/rest-client/rest-client.vcxproj.filters diff --git a/README.md b/README.md index a0eab06..98e3e93 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,22 @@ How to run: make ./test +C++ REST +-------- + +Example based on C++ REST SDK - Casablanca which has support for asyncrhonous calls. +Documentation: http://msdn.microsoft.com/en-us/library/jj969455.aspx +Project page: https://casablanca.codeplex.com/ +This example requires Visual Studio 2013 with NuGet. + +How to run (PowerShell + VS 2013): + + cd rest\\rest-client + ii rest-client.sln + right click the project and select: Manage NuGet Packages for solution + restore C++ REST SDK + CTRL+F5 to run the project + node ---- diff --git a/rest/rest-client/rest-client.sln b/rest/rest-client/rest-client.sln new file mode 100644 index 0000000..e2b5033 --- /dev/null +++ b/rest/rest-client/rest-client.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rest-client", "rest-client\rest-client.vcxproj", "{D14F4DBB-888B-492E-8F4F-AC4F3209F217}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D14F4DBB-888B-492E-8F4F-AC4F3209F217}.Debug|Win32.ActiveCfg = Debug|Win32 + {D14F4DBB-888B-492E-8F4F-AC4F3209F217}.Debug|Win32.Build.0 = Debug|Win32 + {D14F4DBB-888B-492E-8F4F-AC4F3209F217}.Release|Win32.ActiveCfg = Release|Win32 + {D14F4DBB-888B-492E-8F4F-AC4F3209F217}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/rest/rest-client/rest-client/ReadMe.txt b/rest/rest-client/rest-client/ReadMe.txt new file mode 100644 index 0000000..944ba97 --- /dev/null +++ b/rest/rest-client/rest-client/ReadMe.txt @@ -0,0 +1,7 @@ +======================================================================== + CONSOLE APPLICATION : rest-client Project Overview +======================================================================== + +Example of C++ REST SDK Casablanca. +Applications contains simple call to REST service. +For more information pay a visit to: https://casablanca.codeplex.com/ diff --git a/rest/rest-client/rest-client/packages.config b/rest/rest-client/rest-client/packages.config new file mode 100644 index 0000000..38fd4cb --- /dev/null +++ b/rest/rest-client/rest-client/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/rest/rest-client/rest-client/rest-client.cpp b/rest/rest-client/rest-client/rest-client.cpp new file mode 100644 index 0000000..2949521 --- /dev/null +++ b/rest/rest-client/rest-client/rest-client.cpp @@ -0,0 +1,43 @@ +// rest-client.cpp : Simple example which downloads data in asynchronous fashion +// + +#pragma once +#include +#include +#include +#include + +using namespace concurrency; +using namespace concurrency::streams; +using namespace web::http; +using namespace web::http::client; + +int _tmain(int argc, _TCHAR* argv[]) +{ + http_client client(L"http://feeds.feedburner.com/PythonInsider?format=xml"); + http_request request(methods::GET); + std::wcout << "Initializing client" << std::endl; + client.request(request).then([](http_response response) + { + // Perform actions here to inspect the HTTP response... + if (response.status_code() == status_codes::OK) + { + std::wcout << "Ok."; + } else { + std::wcout << "Error."; + } + + std::wcout << " Result code : " << response.status_code() << std::endl; + std::wcout << "Response, reading 512 bytes" << std::endl; + istream bodyStream = response.body(); + container_buffer inStringBuffer; + + return bodyStream.read(inStringBuffer, 512).then([inStringBuffer](size_t bytesRead){ + const std::string &text = inStringBuffer.collection(); + std::wcout << text.c_str(); + }); + }).wait(); + + return 0; +} + diff --git a/rest/rest-client/rest-client/rest-client.vcxproj b/rest/rest-client/rest-client/rest-client.vcxproj new file mode 100644 index 0000000..f286138 --- /dev/null +++ b/rest/rest-client/rest-client/rest-client.vcxproj @@ -0,0 +1,92 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {D14F4DBB-888B-492E-8F4F-AC4F3209F217} + Win32Proj + restclient + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rest/rest-client/rest-client/rest-client.vcxproj.filters b/rest/rest-client/rest-client/rest-client.vcxproj.filters new file mode 100644 index 0000000..d097e3f --- /dev/null +++ b/rest/rest-client/rest-client/rest-client.vcxproj.filters @@ -0,0 +1,28 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Source Files + + + + + + \ No newline at end of file