Questions tagged [actix-web]
488 questions
3
votes
0 answers
Integrate actix websocket with rabbitmq (lapin) in Rust
I've written a websocket server in Rust using actix. If anyone wants to check the full repo here https://github.com/fabracht/actix-websocket.
Now, I want to integrate rabbitmq into the project. For that, I found the lapin crate…

Fabrex
- 162
- 9
3
votes
2 answers
How can I launch a daemon in a websocket handler with actix-web?
Given a basic setup of a WebSocket server with Actix, how can I launch a daemon inside my message handler?
I've extended the example starter code linked above to call daemon(false, true) using the fork crate.
use actix::{Actor, StreamHandler};
use…

lovelikelando
- 7,593
- 6
- 32
- 50
3
votes
1 answer
"there is no reactor running, must be called from the context of a Tokio 1.x runtime" when using mongodb 2 with actix-web 3
I tried to implement mongodb with actix web. This is my main class:
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let db_helper = DbHelper::open_connection().await?;
println!("Connected!");
Ok(())
}
// my db helper
pub…

Kingfisher Phuoc
- 8,052
- 9
- 46
- 86
3
votes
0 answers
Actix web - sqlx - juniper: I got 'Tried to resolve async field users on type Some("Query") with a sync resolver'
I'm trying to use Actix-SQLx-Juniper in my Rust project. I've followed and combined any tutorial that I've found, it successfully compiled and run. But when I try to post a query, I got this error in terminal:
thread 'actix-web' panicked at 'Tried…
3
votes
1 answer
Rust Sqlx handle INSERT ON CONFLICT
I have a query which inserts the data of an user into the db. It works fine, but the users table has an unique index on the username, so when trying to create a row with a username already existing, it throws an error:
pub async fn create(user:…

Johann Esburgo
- 41
- 1
- 6
3
votes
1 answer
POST request using curl to Actix Server failing with "400 Bad Request"
I'm trying to build an actix server using actix-web = "3.3.2" to send a POST request to AWS SES which will send an email to the address provided in the body to the route. I've created a route, called signup which returns a 400 response with the…

AMP_035
- 167
- 1
- 2
- 13
3
votes
1 answer
Rust Actix-Web Example Project with MySQL - Arity > 12 items
I am new to Rust and working with the Actix-Web "advanced" GraphiQL example which uses Juniper and MySQL. I am running into an issue when my model reaches 13 columns it throws an error. This works until I add the 13th column.
#[graphql(description =…

xXPhenom22Xx
- 1,265
- 5
- 29
- 63
3
votes
1 answer
Rust Actix-Web v4 creating a response with custom header
I am trying to create a response inside a handler with actix-web v4.
The header method has changed to append_header which now instead of a key value pair takes a header object.
The original documentation here gives the following example:
use…

Johannes Maria Frank
- 2,747
- 1
- 29
- 38
3
votes
1 answer
How can I pass a json schema as data to actix web?
I want to pass a pre-compiled json schema to actix web, but the compiler complains that the borrowed Value used to create the JSONSchema does not live long enough. Is there a way to workaround this?
Example:
use jsonschema::JSONSchema;
use…

Matt Roberts
- 1,107
- 10
- 15
3
votes
1 answer
Actix Web Consuming %5 Cpu While Idling
I am trying to learn rust atm hence I've created simple todo web app with actix and mongodb and deployed to linux server (ubuntu 18.04) via docker. But I realized, even while no connection/request (ie. right after container start), cpu usage stays…

Blithe
- 105
- 1
- 9
3
votes
2 answers
How to fix "the trait Factory<_, _, _> is not implemented for {function}" error in actix_web?
I have this simple code:
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use serde::{Deserialize, Serialize};
use serde_json::{json};
use validator::{Validate, ValidationError};
#[derive(Deserialize, Serialize,…

sudoExclaimationExclaimation
- 7,992
- 10
- 47
- 105
3
votes
2 answers
How do I create an actix-web server that accepts both sqlx database pools and transactions?
I'm trying to setup a web application using actix-web and sqlx where I can have tests that have their own webserver and database transaction. I've tried to setup my server creation such that it accepts either a database (Postgres) pool or a…

Oskar Persson
- 6,605
- 15
- 63
- 124
3
votes
0 answers
Compiling an application using actix-web + mongo runs out of memory on Linux
I am unable to compile the following on Linux (Ubuntu 18 Bionic Beaver). I have tried both Docker and VirtualBox VMs, but rustc eventually runs out of memory on both. The code compiles without issue on macOS, and compiled on Linux until roughly 5…

AaronP
- 71
- 3
3
votes
1 answer
Run long running async function in background after returning response
In one of my actix-web handlers I want to call a function that run in the background and immediately return a response to the user:
async fn heavy_computation() -> {
// do some long running computation
}
async fn index(req: HttpRequest) -> impl…

Oskar Persson
- 6,605
- 15
- 63
- 124
3
votes
1 answer
Using redis-rs with actix-web
I am trying to add redis as a web::Data context to my actix-web rust application:
extern crate redis;
// std imports
use std::net::SocketAddr;
// external imports
use actix_web::{App, HttpServer};
use redis::Client
#[actix_rt::main]
async fn…

Philipp Molitor
- 387
- 4
- 14