Currently I can only get the error message which is error decoding response body: expected value at line 1 column 1
.
Apparently the reason of error is httpbin.org
was returning HTML. I'm wondering how can I return that HTML to the client.
use actix_web::{get, App, Error, HttpResponse, HttpServer};
use reqwest;
use std::collections::HashMap;
#[get("/")]
async fn index() -> Result<HttpResponse, Error> {
let res = reqwest::get("https://httpbin.org/404")
.await
.expect("Get request failed");
match res.json::<HashMap<String, String>>().await {
Ok(resp) => Ok(HttpResponse::Ok().json(resp)),
Err(e) => {
println!("{:?}", e);
Err(Error::from(HttpResponse::BadRequest().body(e.to_string())))
}
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.run()
.await
}