-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlisten.cpp
More file actions
64 lines (48 loc) · 1.37 KB
/
Copy pathlisten.cpp
File metadata and controls
64 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cpprest/json.h>
#include <cpprest/http_listener.h>
using namespace web;
using namespace http;
using namespace utility;
using namespace http::experimental::listener;
#include "stringBox.h"
class MyListener
{
public:
http_listener listener;
MyListener(string_t address) : listener(address)
{
listener.support(methods::PUT, std::bind(&MyListener::handle_put, this, std::placeholders::_1));
}
pplx::task<void> open() { return listener.open(); }
pplx::task<void> close() { return listener.close(); }
void handle_put(http_request message)
{
message.reply(status_codes::OK)
.wait();
message.extract_json()
.then([=](json::value value)
{
const std::string payload = (StringBox::FromJSON(value.as_object()).string);
std::cout << payload << std::endl;
})
.wait();
}
};
int main(int argc, char** argv)
{
string_t port = U("8080");
if (argc == 2)
{
port = conversions::to_string_t(argv[1]);
}
string_t address = U("http://localhost:");
address.append(port);
address.append(U("/RESTtest"));
MyListener myListener(address);
myListener.open().wait();
std::cout << "Press ENTER to exit." << std::endl;
std::string line;
std::getline(std::cin, line);
myListener.close().wait();
return 0;
}