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!
Obviously this code won't run, just want to gleam the gist of what you want from an example.