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
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,32 +8,32 @@
8
8
9
9
Curly is an efficient thread-ready parallel HTTP client built on top of libcurl.
10
10
11
-
With Curly you can run one or multiple HTTP requests in parallel while either only blocking the calling thread or not blocking at all.
11
+
With Curly you can run one or multiple HTTP requests in parallel and you control how and when you want to block.
12
12
13
13
Some highlights are:
14
14
15
-
* Automatic TCP connection re-use (especially valuable for HTTPS connections).
15
+
* Automatic TCP connection re-use (a big performance benefit for HTTPS connections).
16
16
* Uses HTTP/2 multiplexing when possible (multiple requests in-flight on one TCP connection).
17
17
* Any number of threads can start any number of requests and choose their blocking / nonblocking behavior.
18
-
* Gzip'ed response bodies are transparently uncompressed.
18
+
* Gzip'ed response bodies are transparently uncompressed using [Zippy](https://github.com/guzba/zippy).
19
+
* Control how many requests are allowed in-flight at the same time.
19
20
20
21
By choosing what blocks and doesn't block, you can manage your program's control flow however makes sense for you.
21
22
22
-
## Examples
23
+
### Getting started
24
+
```nim
25
+
import curly
23
26
24
-
NOTE! While these examples include `let curl = newCurl()`, it is strongly suggested that you reuse a single or small number of long-lived Curly instances instead of creating new instances frequently.
27
+
let curl = newCurly() # Best to start with a single long-lived instance
28
+
```
25
29
26
30
### A simple request
27
31
```nim
28
-
let curl = newCurly()
29
-
30
32
let response = curl.post("https://...", headers, body) # blocks until complete
31
33
```
32
34
33
35
### Multiple requests in parallel
34
36
```nim
35
-
let curl = newCurly()
36
-
37
37
var batch: RequestBatch
38
38
batch.post("https://...", headers, body)
39
39
batch.get("https://...")
@@ -42,22 +42,20 @@ for (response, error) in curl.makeRequests(batch): # blocks until all are comple
42
42
if error == "":
43
43
echo response.code
44
44
else:
45
+
# Something prevented a response from being received, maybe a connection
46
+
# interruption, DNS failure, timeout etc. Error here contains more info.
let answer = curl.pollForResponse() # checks if a request has completed
84
82
if answer.isSome:
85
83
if answer.get.error == "":
84
+
echo answer.get.response.request.url
86
85
echo answer.get.response.code
87
86
else:
88
87
echo answer.get.error
@@ -92,7 +91,9 @@ Check out the [examples/](https://github.com/guzba/curly/tree/master/examples) f
92
91
93
92
## Configuration
94
93
95
-
When you create a Curly instance, you can optionally specify `maxInFlight` which will let you control the maximum HTTP requests that will be actively running at any time. This means you can queue 100,000 requests and know that only say 100 of them will be in-flight at a time.
94
+
When you create a Curly instance, you can optionally specify `maxInFlight`. This value lets you control the maximum HTTP requests that will be actively running at any time. The default `maxInFlight` value is 16.
95
+
96
+
Controlling `maxInFlight` is useful because it means you can queue up 100,000 requests and know that only say 100 of them will be in-flight at a time.
96
97
97
98
## Queue management
98
99
@@ -110,7 +111,7 @@ It is a great starting point to simply have `let curl* = newCurly()` at the top
110
111
111
112
## Production tested
112
113
113
-
I have been using Curly in a production web server to make 20k+ HTTPS requests per minute on a tiny VM for a while now without any trouble.
114
+
I am using Curly in a production web server to make 20k+ HTTPS requests per minute on a tiny VM for a while now without any trouble.
114
115
115
116
Both the blocking and non-blocking Curly APIs are used and confirmed working in a very multi-threaded production environment.
0 commit comments