Questions tagged [actix-web]
195 questions
19
votes
7 answers
Cache Rust dependencies with Docker build
I have hello world web project in Rust + Actix-web. I have several problems. First is every change in code causes recompiling whole project including downloading and compiling every crate. I'd like to work like in normal development - it means cache…
![](../../users/profiles/10364449.webp)
Arek C.
- 519
- 4
- 12
13
votes
1 answer
Should diesel be run using a sync actor, actix_web::web::block or futures-cpupool?
Background
I am working on an actix-web application using diesel through r2d2 and am unsure of how to best make asynchronous queries. I have found three options that seem reasonable, but am unsure of which one is best.
Potential Solutions
Sync…
![](../../users/profiles/12343090.webp)
logina
- 209
- 1
- 9
11
votes
5 answers
How can I make protected routes in actix-web
I need to verify if the user has permission for some routes.
I have made 3 "scopes" (guest, auth-user, admin) and now I don't know how to check if the user has access to these routes.
I'm trying to implement auth-middleware and this middleware…
![](../../users/profiles/11731092.webp)
Karol
- 111
- 1
- 7
10
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(|| {
…
![](../../users/profiles/1185053.webp)
dav_i
- 25,285
- 17
- 94
- 128
9
votes
1 answer
How do I resolve "implementation of serde::Deserialize is not general enough" with actix-web's Json type?
I'm writing a server using actix-web:
use actix_web::{post, web, Responder};
use serde::Deserialize;
#[derive(Deserialize)]
struct UserModel<'a, 'b> {
username: &'a str,
password: &'b str,
}
#[post("/")]
pub fn register(user_model:…
![](../../users/profiles/6676654.webp)
thesdev
- 529
- 6
- 14
9
votes
2 answers
How to return an early response from an actix-web middleware?
My clients authorize through a token in the Authorization header which needs to be checked for each request. If this header is missing or I cannot find a corresponding user, I want to return the HTTP code Unauthorized, else I want to handle the…
![](../../users/profiles/8291090.webp)
ThinkPat
- 103
- 1
- 8
8
votes
2 answers
How to run a callback function on actix-web server start?
Currently my main function, where the server starts looks like this
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let address = "0.0.0.0:3000";
HttpServer::new(move || {
let app_state = {...some state};
…
![](../../users/profiles/6772899.webp)
high incompetance
- 1,864
- 3
- 14
- 23
6
votes
1 answer
How do I configure actix-web to accept CORS requests from any origin?
I am building a REST API with actix-web. How do I configure CORS to accept requests from any origin?
Cors::new() // <- Construct CORS middleware builder
.allowed_origin("localhost:8081")
.allowed_methods(vec!["GET", "POST"])
…
![](../../users/profiles/4558302.webp)
Bopsi
- 1,244
- 2
- 25
- 45
5
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',…
![](../../users/profiles/970736.webp)
Matt Roberts
- 1,047
- 10
- 14
5
votes
1 answer
actix_web middleware ErrorHandlers return error message in ServiceResponse
I am trying to capture errors that may occur for requests made to my server.
This came up when I was receiving a 400 on one of my POST requests (which was thrown before even getting to my request handler method) and I was receiving no feedback as…
![](../../users/profiles/4717937.webp)
rpascal
- 613
- 1
- 6
- 19
5
votes
1 answer
Cannot borrow in a Rc as mutable
First of all I'm new with Rust :-)
The problem:
I want to create a module called RestServer that contain the methods ( actix-web ) to add routes and start the server.
struct Route
{
url: String,
request: String,
handler: Box
![](../../users/profiles/1745729.webp)
Andrea Mucci
- 625
- 1
- 7
- 21
5
votes
2 answers
HTTP request inside actix-web handler -> Multiple executors at once: EnterError
When creating a hyper post request inside an actix-web resolver, the following error is thrown - how can one send one a http request by spawning the request into the existing executor?
thread 'actix-rt:worker:1' panicked at 'Multiple executors at…
![](../../users/profiles/6360083.webp)
Techradar
- 2,178
- 2
- 10
- 25
5
votes
4 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…
![](../../users/profiles/11378334.webp)
Samuel Dressel
- 631
- 6
- 21
4
votes
1 answer
How do I pass a Trait as application data to Actix Web?
I want to create a actix-web server where I can provide my Search trait as application data in order to easily swap between multiple implementations or use mock implementation for testing. Whatever I try I can't get it to compile or when I get it to…
![](../../users/profiles/1523238.webp)
Oskar Persson
- 7,267
- 12
- 48
- 107
4
votes
1 answer
How to cache or memoize data in actix-web route?
I have an API I'm implementing where I have an expensive function that needs to be called. I'd like to either memoize this function or use a key value cache to look up previous results. I'd also consider a Mutex or similar structure, but I would…
![](../../users/profiles/1255817.webp)
turtle
- 5,849
- 15
- 57
- 78