News for hackers. Stuff that matters.
Re:Tokio 1.0 – async runtime for Rust by renewiltord on Wednesday December 23, 2020 @06:15PM (#25523398)
Always found these APIs a little hard to work with. For instance, if I tried to use `actix-web`, then using `reqwest` and `tokio` felt like pulling teeth.

If anyone's got minimal code lining up a web framework (any one, not stuck to actix) with some reqwest, I'd be thankful to look over it. Just some trivial stuff so I can add an API gateway that proxies a specific API.

Re:Tokio 1.0 – async runtime for Rust by jayy-lmao on Wednesday December 23, 2020 @07:21PM (#25523874)
I've got a few examples of simple web servers within my company, could backport some of it to a public example. Are you just looking to have something a bit like: ``` #[get('/todo')] async fn getTodos(...) -> impl Responder { let todos = reqwest.get('other-api/todos').await?;

  todos
} ```

Obviously this code won't run, just want to gleam the gist of what you want from an example.

Re:Tokio 1.0 – async runtime for Rust by renewiltord on Wednesday December 23, 2020 @07:39PM (#25524005)
Hey, thank you for offering. Yes! Something minimal like that that doesn't use `reqwest::blocking` would be very helpful.

If it could do the Error case too that would be cool.

For Rocket, I have something like:

    #[get("/list/<status>")]
    fn list_prospects(api_key: ApiKey, status: String) -> Result<Json<PendingList>, Status>
with a

    impl<'a, 'r> FromRequest<'a, 'r> for ApiKey
But I couldn't quickly get an `async` piece in there so I just sucked it up and synced it all up since it's only backing a Retool dashboard so it isn't the end of the world.

So if the example is like:

    #[get('/todo')]
    fn get_todos() -> Result<Json<TodoList>, Status>
      let todos = reqwest...
      Ok(todos)
or the equivalent in the web framework you have that would be hecka useful.
Re:Tokio 1.0 – async runtime for Rust by nicoburns on Wednesday December 23, 2020 @08:13PM (#25524196)
For Rocket you want to use the master branch which has async support. Then your request handler is an async function and you can just .await the future returned by reqwest.
Re:Tokio 1.0 – async runtime for Rust by renewiltord on Wednesday December 23, 2020 @08:46PM (#25524359)
Oh, I must be behind. Should've kept up and tried it. Thank you!
Re:Tokio 1.0 – async runtime for Rust by octoberfranklin on Wednesday December 23, 2020 @09:29PM (#25524538)
The examples in the package docs have always been great starting points for me.

Also, I love the fact that Rust will complain if the examples in your comments don't compile. Such a great feature. As a result, copy-and-pasting examples out of rustdoc pages (nearly) always gives you a working starting point to hack from.

Re:Tokio 1.0 – async runtime for Rust by pat2man on Thursday December 24, 2020 @01:13AM (#25525416)
Actix web has an example that is basically just a proxy. It does use its own client vs reqwest but the principals are the same.