minecraft_utils/mojang_api/
client.rs1use crate::mojang_api::error::ApiError;
2use minreq::{Method, Request, Response, URL};
3
4#[doc(hidden)]
5pub fn fetch<U: Into<URL>>(method: Method, url: U) -> Request {
6 Request::new(method, url).with_header("User-Agent", "minecraft_utils/0.1.0")
7}
8
9#[doc(hidden)]
10pub fn get<U: Into<URL>>(url: U) -> Result<Response, ApiError> {
11 let res = fetch(Method::Get, url).send()?;
12 if res.status_code == 200 {
13 Ok(res)
14 } else {
15 Err(ApiError::Request {
16 status: res.status_code,
17 reason: res.reason_phrase,
18 })
19 }
20}