tactical nuke..no json :(

This commit is contained in:
LinlyBoi
2022-12-25 10:19:11 +02:00
parent 523bae94f2
commit d7a93d5a3f
4 changed files with 34 additions and 36 deletions

View File

@@ -228,28 +228,17 @@ async fn fetch_commit(url: &'static str) -> Result<String, FetchError> {
Ok(text.as_string().unwrap())
}
async fn fetch_driver(url: &'static str) -> Result<CommonDriver, FetchError> {
async fn fetch_driver(url: &'static str) -> Result<String, FetchError> {
let mut opts = RequestInit::new();
opts.method("GET");
//Available request modes: Cors, NoCors, SameOrigin
opts.mode(RequestMode::NoCors); //NoCors because cors simply doesn't work here
opts.mode(RequestMode::Cors); //Cors is required for fetch to work
//initialise request
let request = Request::new_with_str_and_init(url, &opts)?;
//api header for json
request.headers().set("Accept", "application/json")?;
let window = web_sys::window().unwrap();
let window = gloo::utils::window();
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
assert!(resp_value.is_instance_of::<Response>());
let resp: Response = resp_value.dyn_into().unwrap();
//parsing Json response
let fetched_json = JsFuture::from(resp.json()?).await?;
log!(fetched_json.clone());
let fetched_json: JsValue = fetched_json.into();
//parsing into CommonDriver struct
let fetched_json: CommonDriver = fetched_json.into_serde().unwrap();
Ok(fetched_json)
let text = JsFuture::from(resp.text()?).await?;
Ok(text.as_string().unwrap())
}
//renders components above

View File

@@ -51,18 +51,6 @@ struct Stdnt {
gpa: f32,
email: String,
}
//testing this rn
//Component that returns HTML from json fetched from Api yes :D
// async fn fetch_person() -> Html {
// let resp = Request::get("http://libkyy.cf/api/driver/1234")
// .send()
// .await
// .unwrap();
// assert_eq!(resp.status(), 200);
// let driver: CommonDriver = resp.json().await.unwrap();
// let result = driver.use_it();
// return result;
// }
fn main() {
yew::Renderer::<App>::new().render();