ys1r/
http.rs

1use reqwest::blocking::get;
2/// Sends an HTTP GET request to the specified URL and returns the response body as a String.
3///
4/// # Arguments
5///
6/// * `url` - A string slice that holds the URL to send the GET request to.
7///
8/// # Returns
9///
10/// A `Result` containing the response body as a `String` on success, or a `reqwest::Error` on failure.
11pub fn http_get(url: &str) -> Result<String, reqwest::Error> {
12    get(url)?.text()
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn test_http_get() -> Result<(), Box<dyn std::error::Error>> {
21        let res =
22            http_get("https://raw.githubusercontent.com/YumaYX/YS1-R/refs/heads/dev/Cargo.toml")?;
23        assert!(res.contains("[dependencies]"));
24        Ok(())
25    }
26}