I'm trying to use httr2 with paginated results with this endpoint from the Brazilian House of representatives API
https://dadosabertos.camara.leg.br/api/v2/legislaturas
Reading the httr2 man page I figured I should use req_perform_iterative like so:
base_url <- "https://dadosabertos.camara.leg.br/"
path <- 'api/v2'
endpoint <- "/legislaturas"
req <- request(base_url) |>
req_url_path(path) |>
req_url_path_append(endpoint) |>
req_headers(accept = "application/json")
resp <- req |>
req_perform_iterative(
next_req = iterate_with_link_url())
But this gives me an error
Error in pieces[[1]] : subscript out of bounds
After much investigating, it looks like this happens because the links in the Header has an extra comma at the end
resp2 <- req |>
req_perform()
resp2$headers$link
[1] "<https://dadosabertos.camara.leg.br/api/v2/legislaturas>; rel=\"self\",<https://dadosabertos.camara.leg.br/api/v2/legislaturas?pagina=2&itens=15>; rel=\"next\",<https://dadosabertos.camara.leg.br/api/v2/legislaturas?pagina=1&itens=15>; rel=\"first\",<https://dadosabertos.camara.leg.br/api/v2/legislaturas?pagina=4&itens=15>; rel=\"last\","
Not sure if this is a common problem or if I'm making some mistake. I'm guessing I'll need to make a custom next_req function?
I'm trying to use
httr2with paginated results with this endpoint from the Brazilian House of representatives APIhttps://dadosabertos.camara.leg.br/api/v2/legislaturas
Reading the httr2 man page I figured I should use
req_perform_iterativelike so:But this gives me an error
After much investigating, it looks like this happens because the links in the Header has an extra comma at the end
Not sure if this is a common problem or if I'm making some mistake. I'm guessing I'll need to make a custom
next_reqfunction?