-
Notifications
You must be signed in to change notification settings - Fork 51
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
httr2 #1
Comments
(Also note that I probably won't work on this for a while since I have higher priority stuff that I should be working, but this might happen next time I have a couple of days downtime and a good internet connection) |
It has been on my to do list to experiment with async libcurl bindings in order to support many concurrent requests. Something along the lines of jeroen/curl#51 but perhaps a bit simpler, like promises in JavaScript. # New scheduler
pool <- multi_handle()
# Add requests with callback, returns immediately
req("http://url.com") %>% schedule(pool) %>% then(function(x){
print("Done: ", x$status)
})
req("http://url.com") %>% schedule(pool) %>% then(function(x){
print("Another one: ", x$status)
})
# This would block until all request are finished
complete(pool) @jcheng5 and me briefly chatted about using the R event loop rather than something like Only vaguely related to the above :) |
More to say later, but one quick thought to throw out there: I do think it'd be a bummer to no longer have a simple I'm not sure what the right answer is here -- I chatted about this with @hadley who was also on the fence. What do other folks think? |
It feels like that would be easier on everyone. Maybe you should name first packages
This rings true. I have wondered whether it's best to build the pieces first (e.g. the URL), then pass to the verb. Or just do everything at once and write a monster
I agree. And maybe not just for interactive use. When you're reading API docs, it's always in terms of |
@jennybc my main worry about also having a simpler (And progess would be something like |
What if |
@jcheng5 you mean like this example You could certainly start any chain with a string instead of a request, but I think you'd still need to explicitly send the request with |
Will the design of I know you are generally anti- |
@hadley Reading comprehension FTW @craigcitro If |
@jennybc Yes, I'd really prefer not to use options, but I think it won't be as important since with the pipeable syntax, you'd just create a basic prototype request that every function in your package would customise. |
Wrote a first working version of fully async requests in the ‘curl’ package. See the |
Re "Performing the request", it would be nice if the Request API offered a way to specify the behaviour available currently via |
Also need to break up OAuth apis into much smaller pieces as in #432 |
Need API to retrieve all requests performed when a sequence of requests are performed automatically (e.g. during redirects, #445) |
Current logic re: adding token cache file to |
I think the major pieces are either now in place or tracked in issues, so I'm going to close this mega issue 😄 |
httr is a library for two main tasks: creating http requests and parsing the responses. Currently this dichotomoy is a little muddled because:
the request functions. This tends to lead to large request functions that
have many arguments passed in ...
works with a request or a response. This is particuarly confusing for
functions like
content_type()
: does it set the content type ofthe request or extract the content type of the response?
Additionally, httr was designed prior to the pipe and so uses ... rather than functions that modify an object. This makes the API feel rather different to similar APIs (e.g. rvest). It also makes it harder to test, because you can only easily test the result of issuing a request, not the internal request object. Overall the API feels a little dated, and a little underdesigned.
Request API
Basics
Performing the request
The HTTP method doesn't affect the input arguments or the output type, so that suggests that the key API verb should be the output, rather than the HTTP method:
The request verb would default to GET, unless a body was set, in which case it would change to POST. Otherwise, you could override yourself in two ways:
The first form would be most useful when generating partial requests for API wrappers.
Url
Body
Authentication
Headers
Curl
Response API
Basics
Content
Would not have
resp_content_auto()
because I think time has shown that this is a bad idea.New package?
Should be a new package, httr2?
Pros:
two APIs.
Cons:
would deprecate httr).
I think the pros probably outweigh the cons - the API will a sufficiently large change that it's worth starting from scratch.
@craigcitro, @jeroenooms, @jennybc I'd love your thoughts on this, if you have a little spare time.
The text was updated successfully, but these errors were encountered: