DEV Community

Discussion on: YEW Tutorial: 05 Drive through libraries

Collapse
direstrepo24 profile image
direstrepo24 • Edited on

Hi. In api.rs for yew version 0.18, the function "get_response" is:

pub fn get_response(&mut self, callback: Callback<Result<ServerResponse, Error>>) -> Result<FetchTask, Error> {
        let url = format!("http://api.hostip.info/get_json.php");
        let handler = move |response: Response<Json<Result<ServerResponse, Error>>>| {
            let (meta, Json(data)) = response.into_parts();
            if meta.status.is_success() {
                callback.emit(data)
            } else {
                callback.emit(Err(anyhow!(
                    "{}: error getting ip from http://api.hostip.info/get_json.php",
                    meta.status
                )))
            }
        };
        let request = Request::get(url.as_str()).body(Nothing).unwrap();
       FetchService::fetch(request, handler.into())
    }
}
Enter fullscreen mode Exit fullscreen mode