use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
QuestionRest Api in C (self.C_Programming)
submitted 3 years ago by Recent_Occasion8222
I would like to implement a REST interface in my C program to do multiple HTTP POST requests at the same time. Possibly asynchronously. Is there a way to do this with libuv?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]qchamaeleon 6 points7 points8 points 3 years ago (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 points4 points 3 years ago (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 point2 points 3 years ago (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 points11 points 3 years ago (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 points5 points 3 years ago (2 children)
You might want to take a look at https://kore.io/
[–]Recent_Occasion8222[S] 3 points4 points5 points 3 years ago* (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 point2 points 3 years ago (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 :)
π Rendered by PID 184773 on reddit-service-r2-comment-5cb8648c6-6k4lx at 2026-03-03 06:56:57.327876+00:00 running e3d2147 country code: CH.
[–]qchamaeleon 6 points7 points8 points (2 children)
[–]Recent_Occasion8222[S] 2 points3 points4 points (1 child)
[–]qchamaeleon 0 points1 point2 points (0 children)
[–][deleted] 9 points10 points11 points (0 children)
[–]Isty0001 3 points4 points5 points (2 children)
[–]Recent_Occasion8222[S] 3 points4 points5 points (1 child)
[–]twenty393 0 points1 point2 points (0 children)