Skip to content

Conversation

@mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Aug 7, 2023

library(httr2)

cmd <- r"--{curl 'http://example.com' \
  -X 'PATCH' \
  -H 'Content-Type: application/json' \
  --data-raw '{"data":{"x":1,"y":"a","nested":{"z":[1,2,3]}}} ' \
  --compressed}--"
curl_translate(cmd)

Before:

request("http://example.com") %>% 
  req_method("PATCH") %>% 
  req_body_raw("{\"data\":{\"x\":1,\"y\":\"a\",\"nested\":{\"z\":[1,2,3]}}} ", "application/json") %>% 
  req_perform()

After:

request("http://example.com") %>% 
  req_method("PATCH") %>% 
  req_body_raw('{"data":{"x":1,"y":"a","nested":{"z":[1,2,3]}}} ', "application/json") %>% 
  req_perform()

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@hadley
Copy link
Member

hadley commented Aug 8, 2023

Do you want to become an author so you can just merge these yourself? 😄 If so, do another PR adding yourself to the authors list.

@mgirlich
Copy link
Collaborator Author

mgirlich commented Aug 9, 2023

Thanks, done in #270 😄

@mgirlich mgirlich merged commit 6e8748f into r-lib:main Aug 9, 2023
@mgirlich mgirlich deleted the curl_translate-better-string-encoding branch August 9, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants