--libcurl

Curl’s long-standing `--libcurl` option, which generates equivalent C code for any curl command, is drawing renewed attention as a powerful bridge from command-line HTTP calls to embedded library usage. Commenters highlight how this makes libcurl’s API easier to learn, enables “record and customize” workflows similar to Office macros and browser “copy as cURL,” and effectively turns curl into an intermediate representation that tools can translate into many languages. Others contrast such deterministic code generators with LLM-based solutions, debate broader ideas about more interactive, reflective systems and shells, and point to related tools like curlconverter and Hurl that build on curl’s ubiquity.

What --libcurl Does & Why It’s Liked

  • Generates compilable C code using libcurl that mirrors a given curl command.
  • Seen as:
    • Boilerplate generator so you don’t have to learn every libcurl option.
    • “Live” documentation for the library: run a command, see exactly which API calls to make.
    • A smooth path from CLI usage to embedding libcurl in applications.
  • Example workflows: curl … --libcurl file.c then compile with -lcurl, or via make.

Pattern: “Record Actions, Show the Code”

  • Compared to Office VBA macros and other tools that let you perform actions and then inspect generated code.
  • Similar ideas mentioned:
    • Open XML SDK’s code-browsing tool for Office docs.
    • ASM’s ASMifier producing bytecode-manipulating Java code.
  • Desire to see this pattern in GUI system tools (Gnome settings, firewall/network config) that could output equivalent CLI/script commands.

cURL as an Intermediate Representation

  • Browser devtools “Copy as cURL” is heavily used, then converted to:
    • Python (e.g. requests), JavaScript, Go, R (httr2), Postman collections, etc.
  • cURL is effectively a common “IR” for HTTP requests:
    • Widely supported export and import format across tools.
    • More concise than raw HTTP; hides uninteresting headers and defaults.
  • Some note that “Copy as cURL” often includes unnecessary headers.
  • One commenter argues HTTP can do things cURL cannot (e.g., HTTP/1.1 pipelining).

LLMs vs Deterministic Code Generators

  • Joking claims that LLMs make --libcurl obsolete.
  • Strong counterpoint: deterministic generators like --libcurl and other codegen tools are:
    • Predictable, battle-tested, offline, and resource-light.
    • Free from data-collection and training-ethics concerns.
  • Some still combine this with LLMs (e.g., using AI to convert generated C to Python).

Critiques, Limitations, and Safety

  • Reports that some flags (e.g., --upload-file) don’t translate well.
  • Concerns about “too many flags” and feature creep; suggestion of a separate curl-as-libcurl binary.
  • Worry about “more unsafe C on the internet,” countered by:
    • Trust in libcurl’s maturity.
    • Observation that the generated code is simple; real risk is in user-added logic.

Related Tools & Ecosystem

  • Mentions of:
    • Hurl: a CLI test tool built on libcurl with chaining and assertions.
    • Multiple curl→code converters (web and CLI) and their privacy implications.
    • Reflections that needing codegen at all highlights C’s verbosity vs. languages like Python/Node.