diff --git a/backend/api/src/lib.rs b/backend/api/src/lib.rs index 2036f17..3bd8da7 100644 --- a/backend/api/src/lib.rs +++ b/backend/api/src/lib.rs @@ -282,7 +282,7 @@ return Json(res); async fn create_book( Extension(ref conn): Extension, - doc_sent : Form, + Json(doc_sent): Json, ) -> impl IntoResponse { println!("Creating book"); let book: book::Model = book::Model{ diff --git a/frontend/src/main.rs b/frontend/src/main.rs index b463f9c..e34a698 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -2,6 +2,7 @@ use log::info; //use log::Level; use reqwasm::http::Request; use serde::{Deserialize, Serialize}; +use serde_json; use sycamore::futures::spawn_local; use sycamore::prelude::*; //use sycamore::suspense::Suspense; @@ -67,7 +68,7 @@ async fn fetch_books(search: String) -> Result, reqwasm::Error> { async fn add_book(record: BookUI) -> Result { let url = format!("http://localhost:8081/api/create"); - let resp = Request::post(&url).body(serde_wasm_bindgen::to_value(&record).unwrap()).header("content-type","application/x-www-form-urlencoded").send().await?; + let resp = Request::post(&url).body(serde_wasm_bindgen::to_value(&serde_json::to_string(&record).unwrap()).unwrap()).header("content-type","application/json").send().await?; Ok(resp) } @@ -101,7 +102,6 @@ pub fn Header(cx: Scope) -> View { if !task.is_empty() { app_state.search.set(task); app_state.openlibrary.set(true); - println!("Fetching search\n"); info!("Fetching search\n"); value.set("".to_string()); input_ref @@ -121,7 +121,7 @@ pub fn Header(cx: Scope) -> View { h1 { "Search OpenLibrary" } input(ref=input_ref, class="new-todo", - placeholder="What needs to be done?", + placeholder="Search openlibrary", bind:value=value, on:keyup=handle_submit, )