icann_rdap_client/iana/
iana_request.rs

1//! The IANA RDAP Bootstrap Registries.
2
3use icann_rdap_common::httpdata::HttpData;
4use icann_rdap_common::iana::IanaRegistry;
5use icann_rdap_common::iana::IanaRegistryType;
6use icann_rdap_common::iana::RdapBootstrapRegistry;
7use serde::{Deserialize, Serialize};
8use thiserror::Error;
9
10use crate::http::wrapped_request;
11use crate::http::Client;
12
13/// Response from getting an IANA registry.
14#[derive(Debug, Serialize, Deserialize, Clone)]
15pub struct IanaResponse {
16    pub registry: IanaRegistry,
17    pub registry_type: IanaRegistryType,
18    pub http_data: HttpData,
19}
20
21/// Errors from issuing a request to get an IANA registry.
22#[derive(Debug, Error)]
23pub enum IanaResponseError {
24    #[error(transparent)]
25    Reqwest(#[from] reqwest::Error),
26    #[error(transparent)]
27    SerdeJson(#[from] serde_json::Error),
28}
29
30/// Issues the HTTP request to get an IANA registry.
31pub async fn iana_request(
32    registry_type: IanaRegistryType,
33    client: &Client,
34) -> Result<IanaResponse, IanaResponseError> {
35    let url = registry_type.url();
36
37    let wrapped_response = wrapped_request(url, client).await?;
38    let text = wrapped_response.text;
39    let http_data = wrapped_response.http_data;
40
41    let json: RdapBootstrapRegistry = serde_json::from_str(&text)?;
42    Ok(IanaResponse {
43        registry: IanaRegistry::RdapBootstrapRegistry(json),
44        registry_type,
45        http_data,
46    })
47}