0

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!

AMP_035
  • 167
  • 1
  • 2
  • 13
  • It looks like `Request` is a synchronous API. For it to be a future, it would have to be implemented that way. So the calling code isn't the problem. – piojo May 20 '21 at 05:21
  • Why is the title of the question completely different from the contents? – Jmb May 20 '21 at 06:54

0 Answers0