我正在尝试从 Rust subreddit 获取帖子并将响应返回到我的前端。
这是我的App
:
App::new()
.data(Client::default())
.wrap(middleware::Logger::default())
.service(
web::resource("/get/rust/posts").route(web::get().to_async(get_rust_posts))
)
处理函数:
fn get_rust_posts(req: HttpRequest, client: web::Data<Client>) -> impl Future<Item = HttpResponse, Error = Error> {
client.get("http://www.reddit.com/r/rust.json") // create request builder
.header("User-Agent", "Actix-web")
.send() // send http request
.map_err(Error::from)
.and_then(|resp| {
// return resp
})
}
依赖项:
[dependencies]
actix-web = "1.0.7"
futures = "0.1.29"