4 ms·
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 a
by renewiltord 6y ago
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.
- jayy-lmao 6y agoI'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.
- renewiltord 6y agoHey, 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.
- nicoburns 6y agoFor 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.
- renewiltord 6y agoOh, I must be behind. Should've kept up and tried it. Thank you!
- octoberfranklin 6y agoThe 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.
- pat2man 6y agoActix web has an example that is basically just a proxy. It does use its own client vs reqwest but the principals are the same.