Export a Command Line cURL Command to an Executable

It feels like all I do is write code that calls to an API, whether it be in python, C++,  C, Java, Ruby, and so on. It is one of the most common things any software engineer will do; take the input of one function/process and plug it into another.

To start this process, my go-to-tool is cURL, a command line tool and library to transfer data with URL syntax. I’d venture that virtually anyone involved with the software industry has heard of it. It can basically do everything from quick testing if a website is accessable, to accessing an API with authentication tokens and capturing a cookie (and quite a bit more actually).

One thing many people don’t know, is that every cURL command, i.e. something like below:

Can be converted into a c file, which can then be compiled and exeuted, as so:

This outputs a .c file, which can be compiled:

To compile it, we just need ot pass the -lcurl command:

Simple as can be!

With this, it’s pretty easy to at least get started building your own API client library.

I went ahead and did that, and within five minutes I had a little C++ class/library, that worked great for a project I was working on:

It can use some refactoring and generally more work, but it got the job done and within twenty minutes I was able to build start-to-finish a simple application that could connect to the internet using an API token, update and get data, all in C/C++.

Pretty, sweet and probably my favorite functionality of cURL.

If you want access to all the code in this article (with improved comments), visit the github repo.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available

Time limit is exhausted. Please reload the CAPTCHA.