I'm very new to Rust and am trying to make a post request to an internal API. I'm getting the error:
match request.await {
^^^^^^^^^^^^^ `Request<()>` is not a future
= help: the trait `std::future::Future` is not implemented for `Request<()>`
= note: required by `poll`
In my lib.rs
, I have:
pub async fn make_request(path: &str) -> Request<()>{
let request = Request::post(format!("http://localhost:8000/{}", path))
.body(())
.unwrap();
match request.await {
Ok(res) => println!("Response: {}", res.status()),
Err(err) => println!("Error: {}", err),
}
}
which is called in a module with this code:
pub async fn get_names(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body);
make_request("/names");
}
I understand a "future" is equivalent to a JavaScript promise, so I thought the match statement would work, so I tried adding .await()
on the request but am not sure if I have to create a struct to hold the response which I'd implement in make_request
? Again, I'm really new to Rust and any help would be greatly appreciated. Thanks!