httr2 icon indicating copy to clipboard operation
httr2 copied to clipboard

feat: httr2_translate()

Open JosiahParry opened this issue 4 months ago • 3 comments

related: https://github.com/r-lib/httr2/issues/500

Very often I need to translate an httr2 command to a curl command to send to the software developers on my team (often java or js devs) to provide a reproducible example of a challenging / troublesome request that I am encountering in R.

While there is a curl_translate() to go from curl -> httr2 it would be exceptionally helpful if there were an httr2 -> curl translation function.

I could also imagine this being helpful for documentation purposes—e.g. having code tabs in a quarto doc one for httr2 and curl and the curl tab is populated by an httr2_translate() of the httr2_request object.

JosiahParry avatar Aug 19 '25 17:08 JosiahParry

IMO it's going to be hard to justify the work to do this 99% correctly in R given that an LLM will do it for you 95% correctly.

hadley avatar Aug 19 '25 19:08 hadley

Out of curiosity, how would you go about doing this with an llm? I often use req$body and copy and paste the values into URLdecode() then copy and paste user agent headers etc.

Since requests are created dynamically I don’t really see a straightforward path to using an llm

JosiahParry avatar Aug 19 '25 19:08 JosiahParry

I just copy and paste the httr2/curl code and ask it to translate.

hadley avatar Aug 19 '25 19:08 hadley