You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-15Lines changed: 49 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,9 @@ Modern, non-blocking and exception free, header-only HTTP Client library for C++
7
7
8
8
9
9
> [!NOTE]
10
-
> Please read this document before using the library. I know, you don't have time but reading this document will save you time. I mean just this file, it's not long at all. Trial and error will cost you more time.
10
+
> Please read this document before using the library. I know, you don't have time but reading
11
+
> this document will save you time. I mean just this file, it's not long at all. Trial and error
12
+
> will cost you more time.
11
13
12
14
13
15
# Table of Contents
@@ -29,9 +31,11 @@ Modern, non-blocking and exception free, header-only HTTP Client library for C++
29
31
30
32
## How to add it to my project?
31
33
32
-
This is a header only library. So actually, all you need is to add the libcpp-http-client.hpp file in src folder to your project and start using it with #include.
34
+
This is a header only library. So actually, all you need is to add the libcpp-http-client.hpp file
35
+
in src folder to your project and start using it with #include.
33
36
34
-
But this library is a kind of Curl wrapper that uses Curl under the hood. So, you need to add Curl to your project before to use it.
37
+
But this library is a kind of Curl wrapper that uses Curl under the hood. So, you need to add Curl to
38
+
your project before to use it.
35
39
36
40
You can find usage examples in the examples folder, also find a sample CMakeLists.txt file content below.
Below you can see the simplest use case sending QueryString parameters to an API via HTTP GET.
55
59
56
60
> [!TIP]
57
-
> Please do not use it this way, if more than one call will be made . You do not use the non-blocking feature in this way.
61
+
> Please do not use it this way, if more than one call will be made . You do not use the non-blocking
62
+
> feature in this way.
58
63
59
64
```cpp
60
65
#include<fstream>
@@ -78,7 +83,12 @@ int main() {
78
83
79
84
## What does exception free mean?
80
85
81
-
Exception Free means that no exception will be thrown for any call you make to this library. If the URL cannot be found, there is a timeout, there is an authorization problem or another error occurs on the server, the bool typed "succeed" field of the response is returned as false. In addition, the HTTP Status Code value returned from the server is returned in the int typed "statusCode" field and possibly additional error information that may be returned from the server is returned in the string typed "errorMessage" field.
86
+
Exception Free means that no exception will be thrown for any call you make to this library.
87
+
If the URL cannot be found, there is a timeout, there is an authorization problem or another
88
+
error occurs on the server, the bool typed "succeed" field of the response is returned as false.
89
+
In addition, the HTTP Status Code value returned from the server is returned in the int typed
90
+
"statusCode" field and possibly additional error information that may be returned from the server
91
+
is returned in the string typed "errorMessage" field.
82
92
83
93
You can see an example use case below...
84
94
@@ -108,7 +118,9 @@ int main() {
108
118
109
119
## What does non-blocking mean?
110
120
111
-
Let's talk about this through an example. Let's say we call 5 different API methods when our screen opens and each one takes an average of 500 ms. If we call these methods one after another as follows, we will get all the answers in 2.5 seconds in total.
121
+
Let's talk about this through an example. Let's say we call 5 different API methods when our
122
+
screen opens and each one takes an average of 500 ms. If we call these methods one after another
123
+
as follows, we will get all the answers in 2.5 seconds in total.
112
124
113
125
```cpp
114
126
#include<fstream>
@@ -130,7 +142,9 @@ int main() {
130
142
}
131
143
```
132
144
133
-
".get()" call at the end of each line causes us to wait until the server responds. However, if we make the same call as follows, all requests will be processed in parallel and the total time will take approximately 0.5 seconds.
145
+
".get()" call at the end of each line causes us to wait until the server responds. However,
146
+
if we make the same call as follows, all requests will be processed in parallel and the total
147
+
time will take approximately 0.5 seconds.
134
148
135
149
```cpp
136
150
#include<fstream>
@@ -163,7 +177,11 @@ All functions in the library return a future and allow the next line to run with
163
177
164
178
## What about binary data?
165
179
166
-
In the examples so far, we have used the **"textData"** property of the returning response object. However, we need binary data for requests made to binary files such as images. In such cases, we can ensure that the returned data is returned in **"binaryData"** of type ***"std::vector<unsigned char>"*** instead of **"textData"** by passing the value **"true"** to the **"returnAsBinary"** parameter.
180
+
In the examples so far, we have used the **"textData"** property of the returning response object.
181
+
However, we need binary data for requests made to binary files such as images. In such cases,
182
+
we can ensure that the returned data is returned in **"binaryData"** of type
183
+
***"std::vector<unsigned char>"*** instead of **"textData"** by passing the value **"true"**
184
+
to the **"returnAsBinary"** parameter.
167
185
168
186
```cpp
169
187
#include<fstream>
@@ -189,7 +207,8 @@ int main() {
189
207
190
208
## Sending custom HTTP headers
191
209
192
-
If you need to send custom HTTP HEADERs during the request, you can send them in std::map<std::string, std::string> format.
210
+
If you need to send custom HTTP HEADERs during the request, you can send them in
211
+
std::map<std::string, std::string> format.
193
212
194
213
```cpp
195
214
#include<fstream>
@@ -216,7 +235,8 @@ int main() {
216
235
217
236
## POST request with form data
218
237
219
-
Next is submitting form data via HTTP POST. All you have to do is use **"postRequest"** instead of **"getRequest"**. You can pass the form data to the **"payload"** variable as seen in the sample code below.
238
+
Next is submitting form data via HTTP POST. All you have to do is use **"postRequest"** instead
239
+
of **"getRequest"**. You can pass the form data to the **"payload"** variable as seen in the sample code below.
220
240
221
241
```cpp
222
242
#include<fstream>
@@ -242,7 +262,8 @@ int main() {
242
262
243
263
## POST request with JSON data
244
264
245
-
Sending JSON data via HTTP POST is not much different. Just remember to send **"Content-Type"** as **"application/json"** via HTTP HEADER.
265
+
Sending JSON data via HTTP POST is not much different. Just remember to send **"Content-Type"**
266
+
as **"application/json"** via HTTP HEADER.
246
267
247
268
```cpp
248
269
#include<fstream>
@@ -299,18 +320,24 @@ int main() {
299
320
300
321
## Semantic Versioning
301
322
302
-
Versioning of the library is done using conventional semantic versioning. Accordingly, in the versioning made as **MAJOR.MINOR.PATCH**;
323
+
Versioning of the library is done using conventional semantic versioning. Accordingly,
324
+
in the versioning made as **MAJOR.MINOR.PATCH**;
303
325
304
326
**PATCH:** Includes possible Bug&Fixes and improvements. You definitely want to get this.
305
327
306
-
**MINOR:** Additional functionality added via backwards compatibility. You probably want to get this, it doesn't hurt.
328
+
**MINOR:** Additional functionality added via backwards compatibility. You probably want to
329
+
get this, it doesn't hurt.
307
330
308
-
**MAJOR:** Additional functionality that breaks backwards compatibility. You'll need to know what's changed before you get it, and you'll probably have to make changes to your own code. If I publish something like this, I will definitely add the changes required for migration section to the documentation.
331
+
**MAJOR:** Additional functionality that breaks backwards compatibility. You'll need to know
332
+
what's changed before you get it, and you'll probably have to make changes to your own code.
333
+
If I publish something like this, I will definitely add the changes required for migration
334
+
section to the documentation.
309
335
310
336
311
337
## Full function list
312
338
313
-
You can find the complete list of functions in the library below. In fact, they are just overloaded versions of 5 functions in total.
339
+
You can find the complete list of functions in the library below. In fact, they are just
340
+
overloaded versions of 5 functions in total.
314
341
315
342
> [!TIP]
316
343
> All methods and parameters descriptions are also available within the code as comment for IDEs.
@@ -390,3 +417,10 @@ SOFTWARE.
390
417
391
418
392
419
## Contact
420
+
421
+
If you have problems regarding the library, please open an
422
+
[issue on GitHub](https://github.com/lk-libs/libcpp-http-client/issues/new).
423
+
Please describe your request, issue, or question in as much detail as possible
424
+
and also include the version of your compiler and operating system, as well as
425
+
the version of the library you are using. Before opening a new issue, please
426
+
confirm that the topic is not already exists in closed issues.
0 commit comments