@@ -5,10 +5,10 @@ using namespace lklibs;
5
5
6
6
void simpleGet () {
7
7
8
- HttpClient httpClient (" https://httpbun.com/get" );
8
+ HttpRequest httpRequest (" https://httpbun.com/get" );
9
9
10
10
// The simplest but slowest method if multiple calls will be made
11
- auto response = httpClient
11
+ auto response = httpRequest
12
12
.setQueryString (" param1=7¶m2=test" )
13
13
.send ()
14
14
.get ();
@@ -20,14 +20,14 @@ void simpleGet() {
20
20
21
21
void nonBlockingGet () {
22
22
23
- HttpClient httpClient1 (" https://httpbun.com/get" );
24
- HttpClient httpClient2 (" https://httpbun.com/get" );
25
- HttpClient httpClient3 (" https://httpbun.com/get" );
23
+ HttpRequest httpRequest1 (" https://httpbun.com/get" );
24
+ HttpRequest httpRequest2 (" https://httpbun.com/get" );
25
+ HttpRequest httpRequest3 (" https://httpbun.com/get" );
26
26
27
27
// All requests are made one after the other without waiting for a response
28
- auto future1 = httpClient1 .setQueryString (" param1=1¶m2=test1" ).send ();
29
- auto future2 = httpClient2 .setQueryString (" param1=2¶m2=test2" ).send ();
30
- auto future3 = httpClient3 .setQueryString (" param1=3¶m2=test3" ).send ();
28
+ auto future1 = httpRequest1 .setQueryString (" param1=1¶m2=test1" ).send ();
29
+ auto future2 = httpRequest2 .setQueryString (" param1=2¶m2=test2" ).send ();
30
+ auto future3 = httpRequest3 .setQueryString (" param1=3¶m2=test3" ).send ();
31
31
32
32
// Then all the answers are received. Thus, 3 requests are sent in parallel
33
33
auto response1 = future1.get ();
@@ -49,10 +49,10 @@ void nonBlockingGet() {
49
49
50
50
void receiveBinaryData () {
51
51
52
- HttpClient httpClient (" https://httpbun.com/bytes/100" );
52
+ HttpRequest httpRequest (" https://httpbun.com/bytes/100" );
53
53
54
54
// If you need to retrieve binary data such as an image, just call the "returnAsBinary" method
55
- auto response = httpClient
55
+ auto response = httpRequest
56
56
.returnAsBinary ()
57
57
.send ()
58
58
.get ();
@@ -66,10 +66,10 @@ void receiveBinaryData() {
66
66
67
67
void receiveError () {
68
68
69
- HttpClient httpClient (" https://httpbun.com/not_found" );
69
+ HttpRequest httpRequest (" https://httpbun.com/not_found" );
70
70
71
71
// This is an exception free library. If an error occurs, no exception is thrown
72
- auto response = httpClient .send ().get ();
72
+ auto response = httpRequest .send ().get ();
73
73
74
74
// Instead, the succeed field of the response object is set to false
75
75
std::cout << " Succeed: " << response.succeed << std::endl;
@@ -83,10 +83,10 @@ void receiveError() {
83
83
84
84
void sendingHttpHeaders () {
85
85
86
- HttpClient httpClient (" https://httpbun.com/get?param1=7¶m2=test" );
86
+ HttpRequest httpRequest (" https://httpbun.com/get?param1=7¶m2=test" );
87
87
88
88
// You can send custom headers as key-value pairs
89
- auto response = httpClient
89
+ auto response = httpRequest
90
90
.addHeader (" Custom-Header1" , " value1" )
91
91
.addHeader (" Custom-Header2" , " value2" )
92
92
.send ()
@@ -97,10 +97,10 @@ void sendingHttpHeaders() {
97
97
98
98
void simplePostWithFormData () {
99
99
100
- HttpClient httpClient (" https://httpbun.com/post" );
100
+ HttpRequest httpRequest (" https://httpbun.com/post" );
101
101
102
102
// You can send a POST request with form data in the payload
103
- auto response = httpClient
103
+ auto response = httpRequest
104
104
.setMethod (HttpMethod::POST)
105
105
.setPayload (" param1=7¶m2=test" )
106
106
.send ()
@@ -113,10 +113,10 @@ void simplePostWithFormData() {
113
113
114
114
void simplePostWithJSONData () {
115
115
116
- HttpClient httpClient (" https://httpbun.com/post" );
116
+ HttpRequest httpRequest (" https://httpbun.com/post" );
117
117
118
118
// You need to send the "Content-Type" as "application/json" in the HTTP Header, if you need to send json data in the payload
119
- auto response = httpClient
119
+ auto response = httpRequest
120
120
.setMethod (HttpMethod::POST)
121
121
.setPayload (R"( {"param1": 7, "param2": "test"})" )
122
122
.addHeader (" Content-Type" , " application/json" )
@@ -130,10 +130,10 @@ void simplePostWithJSONData() {
130
130
131
131
void simplePutWithFormData () {
132
132
133
- HttpClient httpClient (" https://httpbun.com/put" );
133
+ HttpRequest httpRequest (" https://httpbun.com/put" );
134
134
135
135
// You can send a PUT request with form data in the payload just like POST
136
- auto response = httpClient
136
+ auto response = httpRequest
137
137
.setMethod (HttpMethod::PUT)
138
138
.setPayload (" param1=7¶m2=test" )
139
139
.send ()
@@ -146,10 +146,10 @@ void simplePutWithFormData() {
146
146
147
147
void simpleDeleteWithFormData () {
148
148
149
- HttpClient httpClient (" https://httpbun.com/delete" );
149
+ HttpRequest httpRequest (" https://httpbun.com/delete" );
150
150
151
151
// You can send a DELETE request with form data in the payload just like POST
152
- auto response = httpClient
152
+ auto response = httpRequest
153
153
.setMethod (HttpMethod::DELETE_)
154
154
.setPayload (" param1=7¶m2=test" )
155
155
.send ()
@@ -162,10 +162,10 @@ void simpleDeleteWithFormData() {
162
162
163
163
void simplePatch () {
164
164
165
- HttpClient httpClient (" https://httpbun.com/patch" );
165
+ HttpRequest httpRequest (" https://httpbun.com/patch" );
166
166
167
167
// You can send a PATCH request with QueryString just like GET
168
- auto response = httpClient
168
+ auto response = httpRequest
169
169
.setMethod (HttpMethod::PATCH)
170
170
.setQueryString (" param1=7¶m2=test" )
171
171
.send ()
@@ -178,10 +178,10 @@ void simplePatch() {
178
178
179
179
void ignoreSslErrors () {
180
180
181
- HttpClient httpClient (" https://self-signed-cert.httpbun.com" );
181
+ HttpRequest httpRequest (" https://self-signed-cert.httpbun.com" );
182
182
183
183
// If you need to ignore SSL errors, you can call "ignoreSslErrors" method before sending the request
184
- auto response = httpClient .ignoreSslErrors ().send ().get ();
184
+ auto response = httpRequest .ignoreSslErrors ().send ().get ();
185
185
186
186
std::cout << " Succeed: " << response.succeed << std::endl;
187
187
std::cout << " Http Status Code: " << response.statusCode << std::endl;
0 commit comments