Convert Your Curl Commands to Python, JavaScript, PHP, R, Go, and More with CurlConverter

If you’re coding tools that use APIs or other online services to retrieve or send data, I imagine you’d love to delve into their documentation. Typically, there are code samples that explain how to ‘chat’ with the API, and these examples most often use the curl command. When you’re lucky, there are also examples in Python or JS or even JavaScript, but that doesn’t go any further.

So, how do you save time if you need to write R, Go, C#, Ruby, Rust, Elixir, Java, MATLAB, Dart, CFML, Ansible URI, or JSON?

Well, with the CurlConverter website, you’ll be able to convert all these curl commands into the language of your choice. It is also available with the curlconverter command that you can install on your machine.

For example, this authentication curl command:

curl "" -u "some_username:some_password"

Becomes the following code in DART:

import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  var uname = 'some_username';
  var pword = 'some_password';
  var authn = 'Basic ' + base64Encode(utf8.encode('$uname:$pword'));

  var url = Uri.parse('');
  var res = await http.get(url, headers: {'Authorization': authn});
  if (res.statusCode != 200) throw Exception('http.get error: statusCode= ${res.statusCode}');

Or in C#:

HttpClient client = new HttpClient();

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "");

request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("some_username:some_password")));

HttpResponseMessage response = await client.SendAsync(request);
string responseBody = await response.Content.ReadAsStringAsync();

CurlConverter can interpret Bash syntax, such as ANSI-C strings and piped files. It also knows all the curl arguments (there are over 300 of them!!), including those that have been removed from recent versions (and therefore ignored most of the time). It can also convert JSON data into native objects and generate code that can read it either from a file or an input stream.

See also  Conquer Your Fear of Learning Python: Embrace 'Code With Mu' for Easy Start

Unfortunately, only HTTP is supported, and code generators for other languages are less comprehensive than the generator for Python.

To use curlconverter, you can install it as a JavaScript library with the

npm install curlconverter

Or as a command-line tool like this:

npm install --global curlconverter

Here’s an example of the code generated from this command:

$ curlconverter --data "hello=world"
import requests

data = {
    'hello': 'world',

response ='', data=data)

In short, super convenient for those who want to simplify the process of creating HTTP requests in their favorite language while relying on more familiar curl commands.”

5/5 - (1 vote)

Mohamed SAKHRI

I am Mohamed SAKHRI, the creator and editor-in-chief of Tech To Geek, where I've demonstrated my passion for technology through extensive blogging. My expertise spans various operating systems, including Windows, Linux, macOS, and Android, with a focus on providing practical and valuable guides. Additionally, I delve into WordPress-related subjects. You can find more about me on my Linkedin!, Twitter!, Reddit

Leave a Comment