Official Discord: https://discord.gg/NWpN5mmg3x | Powerful web framework for Rust | https://github.com/actix/actix-web/wiki/FAQ
robjtede on master
tweak migration document (compare)
github-actions[bot] on gh-pages
Deploying to gh-pages from @ 5… (compare)
github-actions[bot] on gh-pages
Deploying to gh-pages from @ f… (compare)
robjtede on test-v0.1.0-beta.13
robjtede on http-test-v3.0.0-beta.13
robjtede on master
prepare actix-http-test release… prepare actix-test release 0.1.… (compare)
github-actions[bot] on gh-pages
Deploying to gh-pages from @ a… (compare)
robjtede on actors-v4.0.0-beta.12
robjtede on master
prepare actix-web-actors releas… (compare)
robjtede on awc-v3.0.0-beta.21
robjtede on master
prepare awc release 3.0.0-beta.… (compare)
robjtede on http-v3.0.0-rc.3
robjtede on master
prepare actix-http release 3.0.… (compare)
Hello, I have a question how to use add a validator for an object passed via json.
My Request Handler looks like this.
pub async fn handle(req_args: web::Json<HashMap<String, String>>, r: HttpRequest, auth: BasicAuth, app_state_wrapper: web::Data<AppStateWrapper<T, F>>) -> impl Responder {
...
}
Now I want to validate that the Strings of the HashMap do not contain controll characters.
struct Wrapper {
#[validate(length(min = 1), custom = "my_validator")]
content: HashMap<String, String>
}
Unfortunatly I can't change the client-side to send this wrapper object.
Do you have any ideas for me how to do this?
Hello there
There is an example https://github.com/actix/examples/tree/master/json/json_decode_error
This example returns error information as a simple text.
Json deserialize error: missing field `name` at line 1 column 16
But it is not so user-friendly. Is it possible to get some struct with error info? E.g:
{
errors: [
{
"field": "name",
"reason": "missing field",
"line": 1,
"column": 16
},
{
"field": "address.countryCode",
"reason": "Wrong country code abcd `ABCD`",
},
{
"field": "age",
"reason": "Should be between 0 and 100 years",
},
{
"field": "email",
"reason": [
"Too long",
"Incorrect email format"
],
}
]
}
Looks like it is a restriction of serde_json
not actix-web
Thanks
impl Handler<MessageChat> for MessageStore {
type Result = Result<(Uuid,), Error>;
fn handle(&mut self, msg: MessageChat, ctx: &mut Self::Context) -> Self::Result {
// Here i need to run async function and getting result
}
}
HttpServer::new(move || {
App::new()
.service(web::scope("/cables")
.service(web::resource("")
.route(web::get().to(utils::get::<Cable>))
.route(web::post().to(utils::add::<Cable>)))
If I give utils::add::<Cable>
the wrong json, like maybe a string instead of a number, actix will just spit back a 400 because I'm assuming the serde part failedHello, I have a question about the Data<T>
we pass to actix web's App
. I want to allow concurrent writing to it with custom RwLock
inside T
.
Basically I have a big Hashmap<String, MyType>
, I want to lock every MyType
to avoir concurrent writing but I don't want to lock the entire Hashmap
Data<T>
object?
RwLock
stuff, thanks !
App
data
and app_data
?
Arc
directly
I'm having some issue with redis
integration. A redis::Connection
needs to be mutable in order to write something (in my case, a queue with XADD
). So I have to use a RwLock
for the redis connection in my app_data
and it slows down the API a lot:
Since the Connection is a Pin<Box<>>
I thought I could also clone it but it doesn't seem to work.
How do other people handle redis connections using actix?
fn call(&self, req: S::Request) -> Self::Future {
TimeoutServiceResponse {
fut: self.service.call(req),
sleep: Sleep::new(clock::now() + self.timeout),
}
}
Request
not found"
call
method should be of type Req
, not of type S::Request
HttpServer.run()
only resolves when we shutdown the webserver.HttpServer::run
cannot be called from a tokio::task::spawn
.#[actix_web::main]
was doing some magic.
std::thread::spawn(move || {
actix_web::rt::System::new().block_on(async move {
...
})
})
Consider an endpoint for post requests via post macro (https://docs.rs/actix-web/3.3.2/actix_web/attr.post.html). For example using #[post("/login")]
.
Is it possible to define the path elsewhere like const LOGIN: &str = "/login"
and use it in the post macro? I would like to collect all endpoints at one place.
I couldn't make it work. I tried #[post(LOGIN)]
and #[post("{}", LOGIN)]
as well as #[post("{LOGIN}")]
but without success.
Cheers