rust-actix

Do a synchronous http client fetch within an actix thread

对着背影说爱祢 提交于 2021-02-11 06:57:19
问题 I have an actix endpoint, and I need to do a synchronous http client fetch to get some results, and return some data. My endpoints cannot use async , so I can't use any .await methods. I've tried using reqwests blocking client in my endpoint like so: { ... let res = reqwest::blocking::get(&fetch_url)? .json::<MyResp>()?; ... But it gives me the error: thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block

Do a synchronous http client fetch within an actix thread

吃可爱长大的小学妹 提交于 2021-02-11 06:57:19
问题 I have an actix endpoint, and I need to do a synchronous http client fetch to get some results, and return some data. My endpoints cannot use async , so I can't use any .await methods. I've tried using reqwests blocking client in my endpoint like so: { ... let res = reqwest::blocking::get(&fetch_url)? .json::<MyResp>()?; ... But it gives me the error: thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block

Specifying associated type in trait that inherits from another trait

不问归期 提交于 2021-01-27 15:01:37
问题 I started working on my first more ambitious Rust project, and struggle with something I did not come across in any of the resources and tutorials I used for learning. The title of the question captures the abstract problem, but for the examples I'll use the concrete examples I am fighting with. For my project, I need to interface with different third-party services, and I decided to use the actix framework as an abstraction for the different actors in my domain. The framework defines the

Get Body of Response in Actix web test request in Rust

青春壹個敷衍的年華 提交于 2020-12-12 05:38:36
问题 I'm building a web api service with rust and actix. I want to test a route and check if the received response body is what i expect. But I'm strugeling with converting the received body (ResponseBody) into a Json/Bson. The called route actually returns application/json. Thanks for your help. let mut app = test::init_service(App::new() .data(AppState { database: db.clone() }) .route("/recipes/{id}", web::post().to(add_one_recipe))).await; let payload = create_one_recipe().as_document().unwrap(

Actix-Web reports “App data is not configured” when processing a file upload

…衆ロ難τιáo~ 提交于 2019-12-23 15:44:50
问题 I'm using the Actix framework to create a simple server and I've implemented a file upload using a simple HTML frontend. use actix_web::web::Data; use actix_web::{middleware, web, App, HttpResponse, HttpServer}; use std::cell::Cell; // file upload functions, the same as you can find it under the // actix web documentation: // https://github.com/actix/examples/blob/master/multipart/src/main.rs : mod upload; fn index() -> HttpResponse { let html = r#"<html> <head><title>Upload Test</title><

How do I convert an async / standard library future to futures 0.1?

妖精的绣舞 提交于 2019-12-11 15:41:53
问题 I want to use the async function to parse the inbound stream progressively, but actix-web requires impl Future<Item = HttpResponse, Error = Error> as the return value. How can I convert the future returned by async function to what actix-web requires? I'm using Rust 1.39 nightly and actix-web 1.0.7. http_srv.rs : use futures::compat::Stream01CompatExt; use futures::future::{FutureExt, TryFutureExt}; use futures::stream::TryStreamExt; use futures01::future::Future; use futures01::stream: