I've ran into the same problem, but it looks like you used an extractor in the function arguments.
I want to do it like you at the beginning: let person = Json::<Student>:extract(req); and I run into the same problems. I want to do it this way, because I can't seem to catch any errors if the data is invalid. I'm not using state or database at the moment, so I can't let it handle the errors.
For example, if I don't specify a struct's field inside my JSON request, I get no response from the server and weirdly also no panic. That doesn't seem very Rust-like. I should get an error. I should be able to handle it, but it just gets ignored for some reason.
error[E0277]: `dyn futures::future::Future<Item=actix_web::Json<students::Student>, Error=actix_web::Error>` doesn't implement `std::fmt::Debug`
--> src\students\mod.rs:62:54
|
62 | println!("Waiting for extraction of json. {:?}", new_student);
| ^^^^^^^^^^^ `dyn futures::future::Future<Item=actix_web::Json<students::Student>, Error=actix_web::Error>` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
I can't seem to resolve that future to anything. Should I use an await macro? I tried doing new_student.wait(), but it seems to block the thread forever.
It's working alright, I am going to be working on the database part next, so it's returning hardcoded data, but has all the endpoints I need. What I'd like to be able to do is respond with a JSON to the client and tell it what caused the error, which field was wrong or what condition was not fulfilled. I don't see how I can do that, because if the JSON extraction fails my handler just doesn't execute
Feel free to comment out diesel in the Cargo.toml! It took me a few good minutes to compile the project for the first time! Use cargo run-script dev for auto-reload if you want to play around.
I think it is what you need. In this example response with a error in case that the POST request is wrong. You can see more about error handler in actix-web in this example project: