I'm trying to implement a simple Actix API, and the first method I'm testing, is one for creating a "book" object in a SQLite database. I've got the up.sql, schema, model and DAO (just for encapsulating the DB code) all writen, but I'm lacking a very important part: input.
So now I have to deal with the handler, which should read the HttpRequest (which will come as a JSON format), and then save the object in the SQLite instance. The problem is βand this is as funny as annoying-, I have no idea how to read, at least in a proper way, the body of the request.
I've seen a solution in which you take the raw bytes and parse them, but I guess there are much better and more simple solutions for just reading a request's body. But I couldn't find anything useful.
pub async fn create_book_handler(req: HttpRequest) -> HttpResponse {
let book: Book = req. <--- what comes here?
books_dao::create_book(&book);
let response = Json(book);
HttpResponse::Ok()
.content_type(ContentType::json())
.json(response)
}