Skip to content

Commit

Permalink
begin move to POST
Browse files Browse the repository at this point in the history
  • Loading branch information
yannikbuhl committed Aug 30, 2024
1 parent 6fcc843 commit 92a9c1b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions R/gen_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,42 @@
#' httr2::resp_body_json()
#' }
#'
# gen_api <- function(endpoint, ...) {
#
# httr2::request("https://www-genesis.destatis.de/genesisWS/rest/2020") %>%
# httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
# httr2::req_url_path_append(endpoint) %>%
# httr2::req_url_query(!!!gen_auth_get(database = "genesis"), ...) %>%
# httr2::req_retry(max_tries = 3) %>%
# httr2::req_perform()
#
# }

gen_api <- function(endpoint, ...) {

httr2::request("https://www-genesis.destatis.de/genesisWS/rest/2020") %>%
httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
url <- "https://www-genesis.destatis.de/genesisWS/rest/2020"
user_agent <- "https://github.com/CorrelAid/restatis"

body_parameters <- list(...)

if (length(body_parameters) > 0) {

req <- httr2::request(url) %>%
httr2::req_body_form(!!!body_parameters)

} else {

req <- httr2::request(url) %>%
httr2::req_body_form(!!!list("foo" = "bar"))

}

req %>%
httr2::req_user_agent(user_agent) %>%
httr2::req_url_path_append(endpoint) %>%
httr2::req_url_query(!!!gen_auth_get(database = "genesis"), ...) %>%
httr2::req_headers("Content-Type" = "application/x-www-form-urlencoded",
"username" = gen_auth_get(database = "genesis")$username,
"password" = gen_auth_get(database = "genesis")$password) %>%
httr2::req_retry(max_tries = 3) %>%
httr2::req_perform()

Expand Down

0 comments on commit 92a9c1b

Please sign in to comment.