Skip to main content

modrinth_wrapper/
client.rs

1use reqwest::{Client as ReqwestClient, header};
2use crate::error::Result;
3
4pub struct Client {
5    pub(crate) http: ReqwestClient,
6    pub(crate) base_url: String,
7}
8
9impl Client {
10    pub fn new(user_agent: &str) -> Result<Self> {
11        let mut headers = header::HeaderMap::new();
12        headers.insert(
13            header::USER_AGENT,
14            header::HeaderValue::from_str(user_agent)
15                .map_err(|_| crate::error::ModrinthError::Api("Invalid User-Agent".into()))?,
16        );
17
18        let http = ReqwestClient::builder()
19            .default_headers(headers)
20            .build()?;
21
22        Ok(Self {
23            http,
24            base_url: "https://api.modrinth.com/v2".to_string(),
25        })
26    }
27}