Questions tagged [actix-web]
488 questions
11
votes
1 answer
Using Actix from a Tokio App: mixing actix_web::main and tokio::main?
Currently I have a main written like the async example for the Reqwest library.
#[tokio::main]
async fn main() -> Result<(), Box> {
We can use the exact example there for this. Now I want to basically add a -l flag to…

Evan Carroll
- 78,363
- 46
- 261
- 468
11
votes
4 answers
How to get the body of a Response in actix_web unit test?
I'm building a web API service with Rust and actix_web.
I want to test a route and check if the received response body is what I expect. But I'm struggling with converting the received body ResponseBody into JSON or BSON. The called route…

zel873ju
- 139
- 2
- 7
11
votes
1 answer
What is the mechanism for converting a function to a trait in Rust?
An example from actix-web is as follows:
use actix_web::{web, App, Responder, HttpServer};
async fn index() -> impl Responder {
"Hello world!"
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
…

dav_i
- 27,509
- 17
- 104
- 136
10
votes
1 answer
Rust actix::web logging all requests
Is there a way to log all requests being received by actix-web irrespective of whether the endpoint exists or not?
It seems I need to use middleware for this, is this the recommended approach?

Allan K
- 379
- 2
- 13
8
votes
3 answers
Rust actix-web: the trait `Handler<_, _>` is not implemented
I've moved from using actix-web 3.x.x to 4.x.x. and the code that's been running perfectly fine before is now throwing this error:
the trait bound `fn(actix_web::web::Query, actix_web::web::Data>) -> impl…

ilmoi
- 1,994
- 2
- 21
- 45
8
votes
1 answer
use of undeclared crate or module, "use crate_name::schema::posts" doesn't always work
I'm trying to learn Rust by using it with actix-web and diesel.
When I try to import/use the schema by using the crate name it only works in the example.rs file but not in the post.rs file. Both files are nested in their own folders and the command…

commonUser
- 599
- 1
- 6
- 17
7
votes
1 answer
How do I use actix-web 3 and rusoto 0.46 together?
When I try to use actix-web 3 and rusoto 0.46 together I get the following runtime error:
thread 'actix-rt:worker:0' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime',…

Matt Roberts
- 1,107
- 10
- 15
7
votes
1 answer
Rust: expected type, found opaque type
I wanted to make an auxiliary function for rendering templates in actix, here's how it looks:
fn render_response(
tera: web::Data,
template_name: &str,
context: &Context,
) -> impl Responder {
match tera.render(template_name,…

Djent
- 2,877
- 10
- 41
- 66
7
votes
1 answer
How can I pass structs from an Actix middleware to the handler?
I'm trying to write an authentication middleware for my Actix application. When validating the request in the middleware, I make a call to a database to retrieve the necessary user data to validate the incoming request. Once the request has been…

Rob123
- 895
- 6
- 10
7
votes
1 answer
Cannot use UUID as a primary key: Uuid: diesel::Expression is not satisfied
I want to have a UUID field as the primary field in a Postgres table, but I get the following error:
error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
--> database/src/models.rs:3:35
|
3 | #[derive(Debug, Clone,…

Ayush Singh
- 1,409
- 3
- 19
- 31
7
votes
1 answer
Run multiple actix app on different ports
I am trying to run two app (one to admin on port 3006 and another to serve data on port 8080).
They shared database pool, cache...
For actix 1.0 i had this working (i don't know if it's the best way to do that) :
let server = Server::build()
//…

Etienne Prothon
- 982
- 10
- 30
7
votes
5 answers
Actix-Web reports "App data is not configured" when processing a file upload
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…

Samuel Dressel
- 1,181
- 2
- 13
- 27
6
votes
2 answers
Actix-web integration tests: reusing the main thread application
I am using actix-web to write a small service. I'm adding integration tests to assess the functionality and have noticed that on every test I have to repeat the same definitions that in my main App except that it's wrapped by the test service:
let…

Ray
- 96
- 4
6
votes
1 answer
actix_web invalid header provided
I am getting this error running an actix-web based server
ERROR actix_http::h1::dispatcher] stream error: Request parse error: Invalid Header provided
The handler code is this:
#[derive(Serialize, Deserialize)]
pub struct Data {
some_data:…

ferd tomale
- 845
- 7
- 20
6
votes
1 answer
How to retrieve the IP address of the client from HttpRequest in actix-web?
Is it possible to obtain the IP address from a HttpRequest argument?
This is my code:
#[get("/collect")]
pub async fn collect(req: HttpRequest) -> impl Responder {
println!("collect {:?}", req);
HttpResponse::Ok()
}
[dependencies]
actix-web…

captain-yossarian from Ukraine
- 31,174
- 3
- 30
- 62