I am trying to make API post requests of JSON to a web server. This task needs to be asynchronous with least overhead. I am currently using CURL with infinite looping in bash and used '&' to make it asynch, which is slow for my task. How do I boost and reduce asynchronous API post task from CURL or without it? Are there any alternative tools that I can implement for this task?

1 Answer 1


Partial answer:

In particular when using https, opening the connection takes a measureable amount of time. If you do many requests, re-using the connection will make it faster.

Putting curl into the background with & just opens connections in parallel, it doesn't re-use an existing connection.

I do not know a tool that can re-use connections from the commandline.

However, you can do it e.g. with libcurl, see e.g. this answer, and many other HTTP client libraries.

libcurl is a C library, so you need to write a C program to perform your API calls, instead of a shell script.

If C is not your thing, pick any other programming language you prefer, as written above.

In particular with libcurl, have a look at the example program under the link provided. Also read the libcurl docs and example programs (google). With the easy libcurl interface, the trick is to get a single handle, and then keep using that handle for all API calls - it will reuse the open connection.

Real concurrent operation will open several connections in parallel. Which may or may not make it faster - the bottleneck is usually the network, and not processing.

  • Since I am new to these concepts. Can you elaborate a little if I can implement asynchronous api post requests with libraries like libcurl? Commented Aug 6, 2021 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .