Questions tagged [actix-web]
488 questions
51
votes
10 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…

Arek C.
- 1,271
- 2
- 9
- 17
32
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…

Karol
- 323
- 1
- 3
- 8
20
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:…

thesdev
- 798
- 9
- 15
18
votes
2 answers
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"])
…

Bopsi
- 2,090
- 5
- 36
- 58
16
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…

logina
- 247
- 1
- 9
15
votes
1 answer
error "/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found"
Here is My Docker File:
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install libssl-dev
RUN apt-get install -y -q build-essential curl
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV…

Jahadul Rakib
- 476
- 1
- 5
- 19
15
votes
2 answers
Why do I get "System is not running" error after upgrading actix-rt to 2.0.2?
I attempted to update to actix_rt 2.0.2 and have since been getting the following error:
thread 'main' panicked at 'System is not running'
Here is my minimal example:
# Cargo.toml
[dependencies]
actix = "0.10"
actix-web = { version = "3.3.2",…

Marcus Ruddick
- 9,795
- 7
- 28
- 43
14
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…

Oskar Persson
- 6,605
- 15
- 63
- 124
14
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

Andrea Mucci
- 747
- 2
- 9
- 25
13
votes
1 answer
Actix Web: Requested application data is not configured correctly. View/enable debug logs for more details
I have a simple application with an HTTP endpoint and a connection to a MongoDB database.
use actix_web::{
middleware, post,
web::{self},
App, HttpServer, Responder,
};
use mongodb::{options::ClientOptions, Client};
use…

Tobias S.
- 21,159
- 4
- 27
- 45
13
votes
2 answers
How to correctly call async functions in a WebSocket handler in Actix-web
I have made some progress with this, using into_actor().spawn(), but I am struggling to access the ctx variable inside the async block.
I'll start with showing a compiling snippet of the web socket handler, then a failing snippet of the handler,…

Saad Attieh
- 1,396
- 3
- 21
- 42
13
votes
1 answer
How to pass many params to rust actix_web route
Is possible to pass more than one parameter into axtic_web route ?
// srv.rs (frag.)
HttpServer::new(|| {
App::new()
.route(
"/api/ext/{name}/set/config/{id}",
web::get().to(api::router::setExtConfig),
)
})
.start();
//…

Piotr Płaczek
- 530
- 1
- 8
- 20
12
votes
2 answers
Error: proc macro `main` not expanded: Cannot create expander for
I want to run a web server with Rust and Actix-Web. After following these steps of their documentation everything works as expected: the server runs on port 8080.
The problem I have is that VSCode shows errors
This error message is shown in the…

Roman Mahotskyi
- 4,576
- 5
- 35
- 68
12
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};
…

high incompetance
- 2,500
- 4
- 18
- 26
12
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…

ThinkPat
- 133
- 1
- 9