pub struct BojClient { /* private fields */ }Expand description
Synchronous BOJ API client.
BojClient uses an internal reqwest-based transport. Use BojClient::new
for defaults or BojClient::with_reqwest_client to inject a customized
reqwest client.
§Examples
use boj_client::client::BojClient;
use boj_client::query::{CodeQuery, Format, Language};
let client = BojClient::new()?;
let query = CodeQuery::new("CO", vec!["TK99F1000601GCQ01000".to_string()])?
.with_format(Format::Json)
.with_lang(Language::En)
.with_start_date("202401")?
.with_end_date("202401")?;
let _response = client.get_data_code(&query)?;Implementations§
Source§impl BojClient
impl BojClient
Sourcepub fn with_reqwest_client(client: Client) -> Self
pub fn with_reqwest_client(client: Client) -> Self
Creates a client from an existing reqwest::blocking::Client.
This can be used to customize timeout, proxy, TLS, and other reqwest settings while keeping the BOJ client API surface stable.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Replaces the base URL used for endpoint calls.
This is mainly intended for tests and non-production environments.
Sourcepub fn get_data_code(&self, query: &CodeQuery) -> Result<CodeResponse, BojError>
pub fn get_data_code(&self, query: &CodeQuery) -> Result<CodeResponse, BojError>
Calls getDataCode and decodes the response into CodeResponse.
§Errors
Returns BojError when request sending fails, response decoding fails,
or when BOJ returns STATUS != 200.
Sourcepub fn get_data_layer(
&self,
query: &LayerQuery,
) -> Result<LayerResponse, BojError>
pub fn get_data_layer( &self, query: &LayerQuery, ) -> Result<LayerResponse, BojError>
Calls getDataLayer and decodes the response into LayerResponse.
§Errors
Returns BojError when request sending fails, response decoding fails,
or when BOJ returns STATUS != 200.
Sourcepub fn get_metadata(
&self,
query: &MetadataQuery,
) -> Result<MetadataResponse, BojError>
pub fn get_metadata( &self, query: &MetadataQuery, ) -> Result<MetadataResponse, BojError>
Calls getMetadata and decodes the response into MetadataResponse.
§Errors
Returns BojError when request sending fails, response decoding fails,
or when BOJ returns STATUS != 200.