@@ -5,10 +5,10 @@ using namespace lklibs;
55
66void simpleGet () {
77
8- HttpClient httpClient (" https://httpbun.com/get" );
8+ HttpRequest httpRequest (" https://httpbun.com/get" );
99
1010 // The simplest but slowest method if multiple calls will be made
11- auto response = httpClient
11+ auto response = httpRequest
1212 .setQueryString (" param1=7¶m2=test" )
1313 .send ()
1414 .get ();
@@ -20,14 +20,14 @@ void simpleGet() {
2020
2121void nonBlockingGet () {
2222
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" );
2626
2727 // 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 ();
3131
3232 // Then all the answers are received. Thus, 3 requests are sent in parallel
3333 auto response1 = future1.get ();
@@ -49,10 +49,10 @@ void nonBlockingGet() {
4949
5050void receiveBinaryData () {
5151
52- HttpClient httpClient (" https://httpbun.com/bytes/100" );
52+ HttpRequest httpRequest (" https://httpbun.com/bytes/100" );
5353
5454 // If you need to retrieve binary data such as an image, just call the "returnAsBinary" method
55- auto response = httpClient
55+ auto response = httpRequest
5656 .returnAsBinary ()
5757 .send ()
5858 .get ();
@@ -66,10 +66,10 @@ void receiveBinaryData() {
6666
6767void receiveError () {
6868
69- HttpClient httpClient (" https://httpbun.com/not_found" );
69+ HttpRequest httpRequest (" https://httpbun.com/not_found" );
7070
7171 // 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 ();
7373
7474 // Instead, the succeed field of the response object is set to false
7575 std::cout << " Succeed: " << response.succeed << std::endl;
@@ -83,10 +83,10 @@ void receiveError() {
8383
8484void sendingHttpHeaders () {
8585
86- HttpClient httpClient (" https://httpbun.com/get?param1=7¶m2=test" );
86+ HttpRequest httpRequest (" https://httpbun.com/get?param1=7¶m2=test" );
8787
8888 // You can send custom headers as key-value pairs
89- auto response = httpClient
89+ auto response = httpRequest
9090 .addHeader (" Custom-Header1" , " value1" )
9191 .addHeader (" Custom-Header2" , " value2" )
9292 .send ()
@@ -97,10 +97,10 @@ void sendingHttpHeaders() {
9797
9898void simplePostWithFormData () {
9999
100- HttpClient httpClient (" https://httpbun.com/post" );
100+ HttpRequest httpRequest (" https://httpbun.com/post" );
101101
102102 // You can send a POST request with form data in the payload
103- auto response = httpClient
103+ auto response = httpRequest
104104 .setMethod (HttpMethod::POST)
105105 .setPayload (" param1=7¶m2=test" )
106106 .send ()
@@ -113,10 +113,10 @@ void simplePostWithFormData() {
113113
114114void simplePostWithJSONData () {
115115
116- HttpClient httpClient (" https://httpbun.com/post" );
116+ HttpRequest httpRequest (" https://httpbun.com/post" );
117117
118118 // 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
120120 .setMethod (HttpMethod::POST)
121121 .setPayload (R"( {"param1": 7, "param2": "test"})" )
122122 .addHeader (" Content-Type" , " application/json" )
@@ -130,10 +130,10 @@ void simplePostWithJSONData() {
130130
131131void simplePutWithFormData () {
132132
133- HttpClient httpClient (" https://httpbun.com/put" );
133+ HttpRequest httpRequest (" https://httpbun.com/put" );
134134
135135 // You can send a PUT request with form data in the payload just like POST
136- auto response = httpClient
136+ auto response = httpRequest
137137 .setMethod (HttpMethod::PUT)
138138 .setPayload (" param1=7¶m2=test" )
139139 .send ()
@@ -146,10 +146,10 @@ void simplePutWithFormData() {
146146
147147void simpleDeleteWithFormData () {
148148
149- HttpClient httpClient (" https://httpbun.com/delete" );
149+ HttpRequest httpRequest (" https://httpbun.com/delete" );
150150
151151 // You can send a DELETE request with form data in the payload just like POST
152- auto response = httpClient
152+ auto response = httpRequest
153153 .setMethod (HttpMethod::DELETE_)
154154 .setPayload (" param1=7¶m2=test" )
155155 .send ()
@@ -162,10 +162,10 @@ void simpleDeleteWithFormData() {
162162
163163void simplePatch () {
164164
165- HttpClient httpClient (" https://httpbun.com/patch" );
165+ HttpRequest httpRequest (" https://httpbun.com/patch" );
166166
167167 // You can send a PATCH request with QueryString just like GET
168- auto response = httpClient
168+ auto response = httpRequest
169169 .setMethod (HttpMethod::PATCH)
170170 .setQueryString (" param1=7¶m2=test" )
171171 .send ()
@@ -178,10 +178,10 @@ void simplePatch() {
178178
179179void ignoreSslErrors () {
180180
181- HttpClient httpClient (" https://self-signed-cert.httpbun.com" );
181+ HttpRequest httpRequest (" https://self-signed-cert.httpbun.com" );
182182
183183 // 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 ();
185185
186186 std::cout << " Succeed: " << response.succeed << std::endl;
187187 std::cout << " Http Status Code: " << response.statusCode << std::endl;
0 commit comments