Last active
September 23, 2022 19:31
-
-
Save benjaminguinaudeau/46652c61adee4469899a4026b873d07c to your computer and use it in GitHub Desktop.
Parse Curl Request from clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_curl_request <- function(){ | |
tot_req <- clipr::read_clip() %>% | |
stringr::str_split("\n") %>% | |
.[[1]] | |
url <- tot_req %>% | |
str_subset("^curl") %>% | |
str_extract("(?<=').*?(?=')") | |
tmp <- tot_req %>% | |
stringr::str_subset("-H") %>% | |
stringr::str_extract("(?<=').*?(?=')") %>% | |
stringr::str_split("\\:\\s+") | |
headers <- map_chr(tmp, 2) | |
names(headers) <- map_chr(tmp, 1) | |
r_code <- glue::glue("httr::GET(url = {url}, httr::add_headers(.headers = {paste(capture.output(dput(headers)), collapse = '')}))") | |
req <- try(httr::GET(url = url, httr::add_headers(.headers = headers))) | |
dt <- tibble(url = url, headers = list(headers), r_code, req = list(req)) | |
return(dt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment