Questions tagged [actix-web]

488 questions
3
votes
1 answer

Send messages to clients with multiple references to websockets

My question here is in the context of using actix-web with Rust. Unfortunately I can't explain this without a somewhat hefty code example, so let me start with that. struct MyWs { game: Arc>, } impl Actor for MyWs { type…
Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
3
votes
1 answer

Serde deserialization of partial structs with actix_web

I have an API endpoint that utilizes actix_web to deserialize an incoming JSON payload (actix_web ultimately uses serde for JSON deserialization). As an example, I have something that looks like this: pub struct IncomingPayload { pub field1:…
Sam Gomena
  • 1,450
  • 11
  • 21
3
votes
0 answers

how to use tokio_postgres in actix-web

So I want to use tokio_postgres in an actix API, I just started and I am having difficulties with sharing the client in my get request. Here is my code: use actix_web::{web, App, HttpServer, HttpResponse}; use tokio_postgres::{NoTls}; use…
julia
  • 139
  • 3
  • 11
3
votes
0 answers

How to send data from a tokio TcpStream using actix-web HttpResponse

I have a TcpStream from which I need to read N bytes and send them as HttpResponse (I will still need to use the stream later on). At the moment I'm using the following code: use futures::channel::mpsc; use actix_web::HttpResponse; use…
Nick
  • 10,309
  • 21
  • 97
  • 201
3
votes
1 answer

How do you tackle the distinct tasks of logging HTTP requests and outputting trace and error messages deeper in your code?

I read this about how to perform logging of HTTP requests in Actix using logging middleware: https://docs.rs/actix-web/1.0.0/actix_web/middleware/struct.Logger.html Now say that I want to also add logging deep within my application using the log…
Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
3
votes
1 answer

How do I pass App data to service route handler function in actix-web when using function decorations?

I found in the docs an example of how to create global state, protected by Mutex, shared among processing threads that is made available to all your route handlers. Perfect! However, I prefer to use attributes attached to my functions to wire up my…
Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
3
votes
1 answer

Why does an actix-web service send text/plain instead of JSON for an auth error?

I made a webservice with actix and I'm trying to implement the auth flow like in Auth Web Microservice with Rust using Actix-Web 1.0 - Complete Tutorial: use std::sync::Arc; use std::sync::Mutex; use actix_cors::Cors; use…
mamcx
  • 15,916
  • 26
  • 101
  • 189
3
votes
1 answer

Calling async reqwest from with actix-web

In my actix-web-server, I'm trying to use reqwest to call an external server, and then return the response back to the user. use actix_web::{web, App, HttpResponse, HttpServer, Responder}; use serde::{Deserialize, Serialize}; use…
Letharion
  • 4,067
  • 7
  • 31
  • 42
3
votes
2 answers

How can I return a configured App in Actix-Web?

I'm using actix-web to create a httpserver with state/data embedded in it. But vscode show me that the create_app function has wrong arguments in its return value type definition App: pub struct App wrong number of type arguments:…
realjin
  • 1,485
  • 1
  • 19
  • 38
3
votes
1 answer

Why does reading from a Rusoto S3 stream inside an Actix Web handler cause a deadlock?

I'm writing an application using actix_web and rusoto_s3. When I run a command outside of an actix request directly from main, it runs fine, and the get_object works as expected. When this is encapsulated inside an actix_web request, the stream is…
Augusto
  • 1,234
  • 1
  • 16
  • 35
3
votes
1 answer

Rust actix-web thread unsafe movement

I'm trying to write an HTTP endpoint using actix-web 1.0. I've reduced the function so that it's just returning the user that is passed to it, but the compiler still gives an error. extern crate actix_web; extern crate chrono; extern crate…
CallMeNorm
  • 2,299
  • 1
  • 16
  • 23
3
votes
1 answer

How to return an error to caller from an actix-web handler with client?

I created a server with actix_web that will connect through GET to another service using actix client and return body on success or error on error. I have been able to return the body but have no clue about how to return the error. This is my…
antonof
  • 109
  • 1
  • 8
3
votes
1 answer

Forward request body to response in Actix-Web

I would like to forward the Actix-Web request body to the response body (something like echo) but it gives a mismatched types error. use actix_web::*; use futures::future::ok; use futures::Future; fn show_request( request:…
David Tex
  • 87
  • 6
2
votes
0 answers

Need help understanding the inner workings of actix-web

Context I have an actix-web server (v 4.0) which has two end-points, namely, /insert and /read These end-points serve as an abstraction to insert to or read from a postgres (v 14.5) table (being used with diesel ORM). Multiple users can query the…
parmesant
  • 73
  • 4
2
votes
0 answers

Unable to get user_id from Actix Web session data after successful login

EDIT: In the original post I was using CookieSession. After reading the comment from Đorđe below, I decided to switch to using redis for session handling. Setting up redis was painless (with some help from gpt) and the sessions are now…
rc_tn
  • 57
  • 1
  • 8