-
Notifications
You must be signed in to change notification settings - Fork 24
/
Sample.RESTClient.h
48 lines (37 loc) · 1.63 KB
/
Sample.RESTClient.h
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
#pragma once
#include "Sample.h"
DEF_SAMPLE(RESTClient)
{
#if defined(VU_INET_ENABLED)
std::tstring header;
header.append(ts("Accept: */*\r\n"));
header.append(ts("Accept-Encoding: *\r\n"));
header.append(ts("Accept-Language: *\r\n"));
header.append(ts("Content-Type: application/json\r\n"));
header.append(ts("Connection: keep-alive\r\n"));
header.append(ts("\r\n"));
vu::http_response response;
vu::RESTClient rest_client(vu::protocol_scheme::https, ts("5f9c32b6856f4c00168c7da2.mockapi.io"), 443);
// get all
rest_client.get(ts("/api/v1/customers"), response, header);
std::cout << vu::decode_const_http_status_A(response.status) << std::endl;
std::cout << response.text << std::endl;
// create one
rest_client.post(ts("/api/v1/customers"), response, "{\"name\":\"name 5\",\"phone\":\"phone 5\"}", header);
std::cout << vu::decode_const_http_status_A(response.status) << std::endl;
std::cout << response.text << std::endl;
// get one
rest_client.get(ts("/api/v1/customers/5"), response, header);
std::cout << vu::decode_const_http_status_A(response.status) << std::endl;
std::cout << response.text << std::endl;
// update one
rest_client.put(ts("/api/v1/customers/5"), response, "{\"name\":\"name 5-x\",\"phone\":\"phone 5-x\"}", header);
std::cout << vu::decode_const_http_status_A(response.status) << std::endl;
std::cout << response.text << std::endl;
// delete one
rest_client.del(ts("/api/v1/customers/5"), response, header);
std::cout << vu::decode_const_http_status_A(response.status) << std::endl;
std::cout << response.text << std::endl;
#endif // VU_INET_ENABLED
return vu::VU_OK;
}