Client http and request

This is the code I’m using to initialise an HTTP client, and I’m using it to make requests to the GitHub API. I’ll post it here.

use crate::model::github_events::Events;
use reqwest::{blocking, Result};
use std::sync::LazyLock;

static CLIENTS: LazyLock<blocking::Client> = LazyLock::new(|| {
    match blocking::Client::builder().build() {
        Ok(value) => value,
        Err(err) => panic!("{err:?}"),
    }
});

pub fn get_user(name_user_github: String) -> Result<Vec<Events>> {
    let uri: String = format!("https://api.github.com/users/{name_user_github}/events");
    let body = CLIENTS.get(&uri).send()?;
    let res: Vec<Events> = body.json()?;
    Ok(res)
}



Any suggestions for improvement? I’m only just beginning to understand how std::sync works.

Many thanks for any suggestions you can offer to help me improve my code

Don't use globals. This is one of the most important lessons you should learn in your career. Use reference counting instead to get cheap clones.

Specifically talking about reqwest's Client, it has an inner Arc, so you don't need to wrap it with an extra Arc to cheaply clone it.

Your code for client initialization can also be improved. There's no need to use the builder if you won't customize the client. Additionally, if you're going to panic, it's more idiomatic to use unwrap or expect instead:

let client = reqwest::blocking::Client::new();
// or
let client = reqwest::blocking::Client::builder().build().unwrap();

Thank you very much for your explanation; it’s very helpful and I’ve learnt a new concept and way of doing things.