r-lib / httr

httr: a friendly http package for R
https://httr.r-lib.org
Other
986 stars 1.99k forks source link

Better documentation for modify_url() #713

Closed AmeliaMN closed 10 months ago

AmeliaMN commented 2 years ago

I haven't used curl in a long time, so I'm relying on the httr documentation to help me know how to make API calls. I suspect the primary userbase of this package is people who are really familiar with curl, so this may not be something the majority of users need, but I could use a bit more documentation for modify_url().

By searching for the list of parameters I found a general page about URLs that explained a lot of the terms. Then, by searching for the most relevant sounding ones on GitHub, I was able to find an example of using path that I could generalize to my usecase. I could imagine a number of approaches to the documentation:

In case it is at all useful (either for the httr team or other novices searching for examples), here are two API calls I have figured out how to make.

First, an API that uses the standard &parameter=value convention for APIs,

res <- GET("https://boardgamegeek.com/xmlapi2/thing?",
  query = list(type = "boardgame", id = 13, comments = 1)
)

Then, another one that just uses slashes in the URL,

res <- GET(
  modify_url("https://ridb.recreation.gov/", path = c("api", "v1", "recareas", "2837")),
  add_headers(
    accept = "application/json",
    apikey = "yourkeyhere"
  )
)

My guess is that both of these calls could be cleaned up if I understood curl/httr better, but they do seem to be functional.

hadley commented 10 months ago

httr has been superseded in favour of httr2, so is no longer under active development. If this problem is still important to you in httr2, I'd suggest filing an issue offer there 😄. Thanks for using httr!