pub mod core;
pub use self::core::*;
#[derive(Debug)]
pub enum Error {
ValidationError(String),
HTTPException(String)
}
pub fn request(endpoint : &str) -> Result<bytes::Bytes, Error> {
let resp = reqwest::blocking::get(format!("https://api.dhravya.me/{}", endpoint)).unwrap();
let status : u16 = resp.status().as_u16();
if status == 200 {
let bytes : bytes::Bytes = resp.bytes().unwrap();
return Ok(bytes);
} else {
if status == 500 {
return Err(Error::HTTPException("Internal Server Error".to_string()));
} else {
return Err(Error::HTTPException("Unknown Error".to_string()));
}
}
}
pub fn _request(url : &str) -> Result<bytes::Bytes, Error> {
let resp = reqwest::blocking::get(url).unwrap();
let status : u16 = resp.status().as_u16();
if status == 200 {
let bytes : bytes::Bytes = resp.bytes().unwrap();
return Ok(bytes);
} else {
if status == 500 {
return Err(Error::HTTPException("Internal Server Error".to_string()));
} else {
return Err(Error::HTTPException("Unknown Error".to_string()));
}
}
}