Questions tagged [actix-web]

488 questions
2
votes
0 answers

How to alias in Rust without explicit lifetimes?

I need a way to make important data read-accessible, thread-safe throughout my application. My web application in Rust with Actix-Web. Permission data is prefetched when the application starts. To be useful, the request cycle must be able to access…
Josh
  • 3,258
  • 2
  • 19
  • 31
2
votes
1 answer

Error communicating with database: IO driver has terminated

I have an API with actix_web and I'm trying to write some tests for it. I want all the tests to share the same pool as the get_pool function resets and then seeds some data into the db. The tests do not need to be executed in order. The structure is…
alakhpc
  • 21
  • 3
2
votes
1 answer

How would I use multiple database clients in an Actix Web Application

I'm on a project where I need to manage connections to both a MongoDB Instance and a PostgreSQL instance. My current idea is to make a custom type that will contain an Arc> and an Arc> in a struct that…
d3rpp
  • 163
  • 1
  • 7
2
votes
0 answers

How to mock function on unit test actix web

I have an api service that has 2 layer: api and repository. The api layer is where the request handling and business logic defined, while repository is a database call functions. I want to mock the database call function on the unit testing of my…
Jay
  • 21
  • 2
2
votes
1 answer

multiple database pools to different databases in actix-web

How do I support multiple database pools to different databases in actix-web? I am currently using this: // database pool for postgres db1 cfg.add_data(web::Data::new(pool.clone)); and I am able to connect to database db1. How do I add another…
ferd tomale
  • 845
  • 7
  • 20
2
votes
0 answers

call an async function in actix-web middleware

I implemented a actix-web middleware but i'm having issues trying to retrieve a client object from a database pool because that call is an async function: impl Service for SomeMiddleware ... fn call(&self, request:…
ferd tomale
  • 845
  • 7
  • 20
2
votes
0 answers

How can I use the Connection Manager on Redis?

extern crate redis; use redis::aio::ConnectionManager; use std::env; pub async fn connect() -> redis::aio::ConnectionManager { let redis_host_name = env::var("REDIS_HOSTNAME").expect("Missing environment variable REDIS_HOSTNAME"); …
Jeyko22
  • 21
  • 2
2
votes
1 answer

actix-web: Add data to request in middleware

I am learning actix-web, I parsed jwt in middleware, I want to pass the data in jwt to the controller that parses to handle this request, but I don't know how to do it my middleware: use actix_web::{error::ErrorUnauthorized, Error}; use…
januw a
  • 2,056
  • 5
  • 18
  • 39
2
votes
1 answer

Status Codes and Headers not working in actix web

I am trying to return a response via the HTTPResponseBuilder but even when I am using a custom status_code say 307 and a header of Location: google.com, my browser is not redirecting me to the same website. Here is the sample code that I using: …
Sanskar Jethi
  • 544
  • 5
  • 17
2
votes
1 answer

Rust Diesel one to one relationship

hey i'm creating an api to return users with their profile i have two table from two separate database , users and profiles fn handle( &mut self, query_strings: SearchUsersQueryStrings, _: &mut SyncContext, ) ->…
ArtixModernal
  • 661
  • 2
  • 8
  • 21
2
votes
1 answer

How do I configure app_data() for actix_web()

In my code I have this main function: #[actix_web::main] async fn main() -> Result<(), StdErr> { // loads env variables from .env dotenv::dotenv().ok(); actix_web::HttpServer::new(move || { let cors =…
2
votes
0 answers

How do I set trusted Sectigo SSL on a Actix server in RUST?

Based on my code using a .pem SSL certificate and key, I would like to know how I can use a Sectigo SSL that has Root CA Certificate - AAACertificateServices.crt, Intermediate CA Certificate - USERTrustRSAAAACA.crt, Intermediate CA Certificate -…
Mathe Eliel
  • 658
  • 2
  • 6
  • 16
2
votes
1 answer

web::block() fails with "`NonNull` cannot be shared between threads safely"

#[macro_use] extern crate diesel; use diesel::result::Error; use actix_web::web; use diesel::{PgConnection, QueryDsl, RunQueryDsl}; use r2d2::{Pool, PooledConnection}; use r2d2_diesel::ConnectionManager; use schema::tests::dsl::*; pub mod…
porton
  • 5,214
  • 11
  • 47
  • 95
2
votes
1 answer

What's the proper way to call a async function in another async function?

I try write my first rust web demo with actix-web. I copied the example in actix-web welcome web page and changed it as below: use actix_web::{get, App, HttpRequest, HttpServer, Responder}; use std::io::Result; #[get("/{name}")] async fn greet(req:…
sh1yu
  • 75
  • 1
  • 5
2
votes
1 answer

How to efficiently serve a file with actix-web

In actix-web, it is possible to serve a file by returning in a handler: HttpResponse::Ok().streaming(file) But here, file must implement the Stream> trait. The File type from the crate async_std does not implement it, so I…
uben
  • 1,221
  • 2
  • 11
  • 20