Getting content type error #3097
Answered
by
robjtede
thexeromin
asked this question in
Q&A
-
Getting content type error in response when saving something in mongodb. #[post("/")]
async fn add_link(client: web::Data<Client>, form: web::Form<Links>) -> impl Responder {
let collection: Collection<Links> =
client.database(DB_NAME).collection(COL_NAME);
let new_doc = Links {
id: None,
..form.into_inner()
};
let result = collection.insert_one(new_doc, None).await;
match result {
Ok(v) => {
println!("{:#?}", v);
HttpResponse::Ok().body("Link added")
}
Err(err) => HttpResponse::InternalServerError().body(err.to_string())
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
robjtede
Aug 4, 2023
Replies: 1 comment 3 replies
-
Can you include the error in the quesion, please? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
form: web::Form<Links>
means the request needs to be of typeapplication/x-www-form-urlencoded
like that from a basic HTML form.See docs: https://docs.rs/actix-web/latest/actix_web/web/struct.Form.html#extractor