Skip to content
koducathome

cURL to R httr2 Converter

Convert curl commands to R code using httr2. Paste a command and the httr2 snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The R httr2 code appears instantly; other R libraries (httr) are in the tabs above the code.
  3. Set up: Install with install.packages("httr2").
  4. Run it: Run the script in R 4.1+ (it uses the native |> pipe) or RStudio. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no httr2 equivalent.

Example

GET with headers → R httr2

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
R httr2
library(httr2)

response <- request("https://api.example.com/v1/users?page=2") |>
  req_headers(
    "Accept" = "application/json",
    "Authorization" = "Bearer YOUR_TOKEN"
  ) |>
  req_error(is_error = function(resp) FALSE) |>
  req_perform()

print(resp_status(response))
cat(resp_body_string(response), "\n")

Common use cases

  • New R code calling APIs
  • Data collection pipelines

Converting curl to R httr2

httr2 is the modern successor to httr, with pipeable request building.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent httr2 code. Options that have no httr2 equivalent are listed under the editors rather than silently dropped.

Other libraries for R, each with its own page: httr.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Why req_error(is_error = …)?

httr2 turns 4xx/5xx into R errors by default; this returns them as responses, like curl.

How do I parse a JSON response?

Use resp_body_json(response).

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.