freya-components 0.4.0

Components for Freya apps
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use freya_core::prelude::*;
use reqwest::blocking::Client;

/// Shared blocking HTTP client used to fetch remote assets.
pub(crate) struct Http;

impl Http {
    /// Returns the shared [`Client`], lazily creating it in the root context on first use.
    pub(crate) fn get() -> Client {
        try_consume_root_context::<Client>().unwrap_or_else(|| {
            let client = Client::builder()
                .build()
                .expect("Failed to build the HTTP client.");
            provide_root_context(client.clone());
            client
        })
    }
}