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…
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…
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…
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(|| { …
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:…
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…
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}; …
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"]) …
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',…
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…
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
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…
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…
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…
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…
turtle
  • 5,849
  • 15
  • 57
  • 78
1
2 3
12 13