use serde::{Deserialize, Serialize}; async fn get(path: String) -> Result, Box> { dbg!(&path); let api = String::from("https://api.modrinth.com/v2/"); //let api = String::from("localhost:8080/"); //let api = String::from("https://www.rust-lang.org/"); let url = format!(r#"{}{}"#, api, path); println!("{}", &url); let data = reqwest::get(r#"https://api.modrinth.com/v2/projects?ids=["kYuIpRLv","89Wsn8GD"]"#) .await? .bytes() .await? .to_vec(); //println!("body = {:?}", data); Ok(data) } #[derive(Debug, Deserialize)] pub struct Project { pub slug: String, pub title: String, pub description: String, pub categories: Vec, pub client_side: Side, pub server_side: Side, pub body: String, pub additional_categories: Option>, pub project_type: Type, pub downloads: u32, pub icon_url: Option, pub id: String, pub team: String, pub moderator_message: Option, pub published: String, pub updated: String, pub approved: Option, pub followers: u32, pub status: Status, pub license: License, pub versions: Vec, } #[derive(Debug, Deserialize)] pub struct License { pub id: String, pub name: String, pub url: Option, } #[derive(Debug, Deserialize)] pub struct ModeratorMessage { pub message: String, pub body: Option, } #[allow(non_camel_case_types)] #[derive(Debug, Deserialize)] pub enum Side { required, optional, unsupported } #[allow(non_camel_case_types)] #[derive(Debug, Deserialize)] pub enum Type { r#mod, modpack, recourcepack } #[allow(non_camel_case_types)] #[derive(Debug, Deserialize)] pub enum Status { approved, rejected, draft, unlisted, archived, processing, unknown } pub async fn project(name: &str) -> Project { let url = format!("project/{}", name); let data = get(url); serde_json::from_slice(&data.await.unwrap()).unwrap() } pub async fn projects(ids: Vec<&str>) -> Vec { let all = ids.join(r#"",""#); let url = format!(r#"projects?ids=["{}"]"#, all); println!("{}", url); let data = get(url); serde_json::from_slice(&data.await.unwrap()).unwrap() }