Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert observational data functions from httr to httr2 #49

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Aariq
Copy link
Collaborator

@Aariq Aariq commented Nov 20, 2024

The first piece of work transitioning from httr to httr2. This creates a base_req in zzz.R that is then used in all the modified functions to form the basic request. It includes only the API URL and a user agent for now, but could include rate limiting, retry, etc.

Most functions are updated in the same way—instead of npn_GET(<endpoint>, <query args>, ...) they are now formed like:

#form the request
req <- base_req %>%
    httr2::req_url_path_append("endpoint.json") %>%
    httr2::req_url_query(arg = arg)
#perform the request
resp <- httr2::req_perform(req)
#get the results as a data frame
out <- httr2::resp_body_json(resp)
#return as a tibble
tibble::as_tibble(out)

Possible breaking changes include:

  • Several functions return tibbles now instead of data.frames. Tibbles are also data.frames, so this usually doesn't cause a problem. Where it might cause issues for users is when functions previously returned NULL (e.g. if there was an error) they now return a 0x0 tibble. I personally think this is an improvement, but we could keep the old behavior.
  • The ... argument to functions no longer does anything (more in What to do about ... in npn_GET()? #46)
  • npn_get_phenophases_for_taxon() now returns a tibble instead of a list (the documentation said it returned a data frame so I assumed this was a bug)
  • npn_species_state() now errors instead of returningNULL when arguments are invalid. It sounded like this is the intended behavior from the documentation, but could mess up people's workflows

Merge commit 'f82ed20618f5c4e1879df7317b010eac8f4c2ac8'

#Conflicts:
#	.Rbuildignore
#	DESCRIPTION
#	tests/fixtures/npn_species_search_1.yml
#	tests/fixtures/npn_species_search_2.yml
#	tests/fixtures/npn_species_state_1.yml
#	tests/fixtures/npn_species_state_2.yml
#	tests/fixtures/npn_stations_1.yml
#	tests/fixtures/npn_stations_2.yml
#	tests/fixtures/npn_stations_by_location_1.yml
#	tests/fixtures/npn_stations_with_spp_1.yml
#	tests/fixtures/npn_stations_with_spp_2.yml
@Aariq Aariq changed the title Convert httr to httr2 Convert observational data functions from httr to httr2 Nov 20, 2024
@Aariq Aariq marked this pull request as ready for review November 20, 2024 23:41
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.

1 participant