Conversation
Since `req_url_relative()` is a more general interface. And improve `req_url()` docs, links, and examples. Part of #625
|
@hadley I'm definitely concerned, but I haven't played with the new modifiers yet. I regularly use |
|
I don't think I'll use library(httr2)
library(waldo)
# In my real use-case, this also includes auth + a special `Linkedin-Version`
# header required by LinkedIn.
li_base <- httr2::request("https://api.linkedin.com/rest")
# In pretty much all of my {httr2} code, I then append a path to the base
# request, eg:
current <- li_base |>
httr2::req_url_path_append("posts")
# This loses part of the "base" request url.
relative <- li_base |>
httr2::req_url_relative("posts")
waldo::compare(current$url, relative$url)
#> `old`: "https://api.linkedin.com/rest/posts"
#> `new`: "https://api.linkedin.com/posts"
# This technically works but I didn't expect it to from the docs. I prefer to
# keep method + path abstracted as separate steps, but this lets me get pretty
# close.
template <- li_base |>
httr2::req_template("/posts")
waldo::compare(current$url, template$url)
#> ✔ No differencesCreated on 2025-01-06 with reprex v2.1.1 I think I'd prefer something like maybe So, for this particular PR... probably fine? But I don't think it will have the expected effect on my code. |
|
You could use |
|
Regardless, I'm convinced that this is too aggressive, so I won't do it. |
Aha! It seemed like it SHOULD work, so I'm glad there's a way. I feel like it's easy to ignore that distinction (or at least I hope it is, since I missed it!), particularly since that slash so often doesn't mean anything in the browser (for example, https://github.com/jonthegeek and https://github.com/jonthegeek/ go to the same place). I assume there's good reason for those to be seen as different by Oh, but this is also seen as different: li_base <- httr2::request("https://api.linkedin.com/rest/")
current <- li_base |>
httr2::req_url_path_append("posts")
relative2 <- li_base |>
httr2::req_url_relative("/posts")
waldo::compare(current$url, relative2$url)
#> `old`: "https://api.linkedin.com/rest/posts"
#> `new`: "https://api.linkedin.com/posts" That completely makes sense for current <- li_base |>
httr2::req_url_path_append("posts")
current2 <- li_base |>
httr2::req_url_path_append("/posts")
waldo::compare(current$url, current2$url)
#> ✔ No differences
I like the idea of li_base <- httr2::request("https://api.linkedin.com/rest/")
li_base |>
httr2::req_url_path_append("/posts") |>
httr2::req_url_relative("../other") |>
_$url
#> [1] "https://api.linkedin.com/other"
li_base |>
httr2::req_url_path_append("/posts/") |>
httr2::req_url_relative("../other") |>
_$url
#> [1] "https://api.linkedin.com/rest/other"I think I'm expecting it to work more like {fs}: fs::path("mydir") |>
fs::path("another") |>
fs::path("../other") |>
fs::path_norm() # to get it to collapse the ..
#> mydir/otherI think ultimately my issue is with curl::curl_parse_url("../other", "https://myurl.com/rest/posts")$url
#> [1] "https://myurl.com/other" |
Since
req_url_relative()is a more general interface. And improvereq_url()docs, links, and examples.Part of #625
@jonthegeek what do you think of this? I'm wondering if it's too aggressive and maybe I should only deprecate
req_url_path_append().