Created
May 25, 2020 23:27
-
-
Save dzharii/712ff9b9655599636f59e495107d3d40 to your computer and use it in GitHub Desktop.
microsoft_rest_sdk_hello_world_example.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cpprest/http_listener.h> | |
#include <cpprest/json.h> | |
using http_listener = web::http::experimental::listener::http_listener; | |
using methods = web::http::methods; | |
using http_request = web::http::http_request; | |
using status_codes = web::http::status_codes; | |
using http_response = web::http::http_response; | |
void handle_get(http_request request) | |
{ | |
http_response response(status_codes::OK); | |
response.headers().set_content_type(L"text/html"); | |
response.set_body(L"<h1>Hello world!</h1>"); | |
request.reply(response); | |
} | |
int main() | |
{ | |
http_listener listener(L"http://localhost:5050/"); | |
listener.support(methods::GET, handle_get); | |
try | |
{ | |
listener | |
.open() | |
.then([&listener]() {std::wcout << L"\nstarting to listen\n"; }) | |
.wait(); | |
while (true); | |
} | |
catch (std::exception const& e) | |
{ | |
std::wcout << e.what() << std::endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment