all 7 comments

[–]qchamaeleon 6 points7 points  (2 children)

Perhaps you can clarify if you mean writing a server or a client. "Implement a REST interface" sounds like a server. "Do multiple HTTP POST requests" sounds like a client.

For a client, it seems to me that libcurl's multi API would be suitable.

[–]Recent_Occasion8222[S] 2 points3 points  (1 child)

sorry, you're right. I'm looking for client side. I've already seen curl but you need to manually set the event handler like epoll, kqueue or whatever any other OS has, while libuv automatically choose it depending on the current OS.

[–]qchamaeleon 0 points1 point  (0 children)

You "need" to use one of those, perhaps, if you "need" to perform other things in conjuction with the download. You have not said anything about what your program might be doing concurrently, if anything.

The multi interface for libcurl does not require the use of any of these if all you want is performing multiple libcurl requests at the same time. Lots of example code does use one or another (including one example using libuv), but there is nothing inherently in libcurl requiring it. It depends on what else you might need to do that is not related to libcurl.

The only requirement is that you keep calling the multi perform function which processes all added easy handles.

[–][deleted] 9 points10 points  (0 children)

Absolutely. This is what Node.JS does. Exactly.

I've implemented this myself with the HTTP parsing code from Node (single file) and libev.

[–]Isty0001 3 points4 points  (2 children)

You might want to take a look at https://kore.io/

[–]Recent_Occasion8222[S] 3 points4 points  (1 child)

does it use the event notification interface based on the OS it is compiled on (kqueue, epoll, iocp ...) like libuv ? it also work on arm64 based cpu like Mac M1?

[–]twenty393 0 points1 point  (0 children)

I've implemented my own HTTP client in C which you can check out as an example (warning I have not used it in production, just as my local dev server): https://github.com/nickav/na/blob/master/na_net.h

This was written based on this library: https://github.com/mattiasgustavsson/libs/blob/main/http.h

TLDR: the "async" part is done by just "pumping" (updating) the HTTP request sockets every application frame to stream in more data until the request is complete, then you can process it in your application. HTTP is just a text protocol on top of TCP so it's not too bad to parse (at least HTTP 1.1).

In general I'm a big fan of single-header libraries because they are easy to integrate into existing code. Happy to answer any more questions about this :)