I'm trying to create a backend using the Rocket crate:
fn main() {
rocket::ignite().mount("/", routes![helloPost]).launch();
}
#[derive(Debug, PartialEq, Eq, RustcEncodable, FromForm)]
struct User {
id: i64,
USR_Email: String,
USR_Password: String,
USR_Enabled: i32,
USR_MAC_Address: String
}
#[post("/", data = "<user_input>")]
fn helloPost(user_input: Form<User>) -> String {
println!("print test {}", user_input);
}
When I run cargo run
everything works but, when I send a POST request with postman for testing, I get this error:
POST /:
=> Matched: POST / (helloPost)
=> Warning: Form data does not have form content type.
=> Outcome: Forward
=> Error: No matching routes for POST /.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
I've set the header content type to JSON and with other languages that works, but with Rocket I can't get it to work.
This is my JSON body:
{
"USR_Email": "test@test.it",
"USR_Password": "500rockets",
"USR_Enabled": 0,
"USR_MAC_Address": "test test"
}
How can fix this?