Http request in async_std task?

I have some data in my program (which is a web server using async-std and tide) that I want to periodically update from another http server. So I try to async_std::task::spawn a function to fetch the data and replace my local data.

Currently, I use hreq to do the actual fetching. But that means that inside my task, there is a hreq::ResponseFuture to await, and that is not Send.

So I guess I have two alternative questions:

  • Is there a way to get around this, by somehow localizing the ResponseFuture to execute in a single thread or someting? a section of the async book seems to say there isn't, and that kind of makes sense.
  • Is there a http client crate that works with async-std where the request and response types is Send so it can be used in a task?

Wait, it isn't Send? That makes it pretty much useless in async code. Most http libraries are designed for Tokio, but I think surf works with async-std.

I checked surf first, but it required old copies of lots of the async dependencies. Trying 2.0.0-alpha.7 now and it looks hopefull.

Thanks!

Got it working nicely with surf-2.0.0-alpha.7, Thanks again @alice!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.