pub struct ResoClient { /* private fields */ }Expand description
RESO Web API client
Implementations§
Source§impl ResoClient
impl ResoClient
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new client from environment variables
§Environment Variables
RESO_BASE_URL- Base URL of the RESO server (required) Example:https://api.mls.com/api/v2/ODataRESO_TOKEN- OAuth bearer token (required)RESO_DATASET_ID- Dataset ID for URL path (optional)RESO_TIMEOUT- Timeout in seconds (optional, default: 30)
§Examples
let client = ResoClient::from_env()?;Sourcepub fn with_config(config: ClientConfig) -> Result<Self>
pub fn with_config(config: ClientConfig) -> Result<Self>
Create a new client with manual configuration
§Examples
let config = ClientConfig::new(
"https://api.mls.com/reso/odata",
"your-token"
);
let client = ResoClient::with_config(config)?;Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
Get the base URL
§Examples
let config = ClientConfig::new("https://api.mls.com/odata", "token");
let client = ResoClient::with_config(config)?;
assert_eq!(client.base_url(), "https://api.mls.com/odata");Sourcepub async fn execute(&self, query: &Query) -> Result<Value>
pub async fn execute(&self, query: &Query) -> Result<Value>
Execute a query and return raw JSON
Executes a standard OData query and returns the full JSON response.
The response follows the OData format with records in a value array.
§Examples
let query = QueryBuilder::new("Property")
.filter("City eq 'Austin'")
.select(&["ListingKey", "City", "ListPrice"])
.top(10)
.build()?;
let results = client.execute(&query).await?;
// Access records from OData response
if let Some(records) = results["value"].as_array() {
for record in records {
println!("{}", record["ListingKey"]);
}
}
// Access count if requested with with_count()
if let Some(count) = results["@odata.count"].as_u64() {
println!("Total: {}", count);
}Sourcepub async fn execute_by_key(&self, query: &Query) -> Result<Value>
pub async fn execute_by_key(&self, query: &Query) -> Result<Value>
Execute a direct key access query and return a single record
Direct key access queries (e.g., Property('12345')) return a single object
instead of an array wrapped in {"value": [...]}. This method is optimized
for such queries.
§Examples
// Fetch a single property by key
let query = QueryBuilder::by_key("Property", "12345")
.select(&["ListingKey", "City", "ListPrice"])
.build()?;
let record = client.execute_by_key(&query).await?;
// With expand
let query = QueryBuilder::by_key("Property", "12345")
.expand(&["ListOffice", "ListAgent"])
.build()?;
let record = client.execute_by_key(&query).await?;Sourcepub async fn execute_count(&self, query: &Query) -> Result<u64>
pub async fn execute_count(&self, query: &Query) -> Result<u64>
Execute a count-only query and return the count as an integer
Uses the OData /$count endpoint to efficiently get just the count
without fetching any records. More efficient than using with_count()
when you only need the count.
§Examples
let query = QueryBuilder::new("Property")
.filter("City eq 'Austin'")
.count()
.build()?;
let count = client.execute_count(&query).await?;
println!("Total properties in Austin: {}", count);Sourcepub async fn fetch_metadata(&self) -> Result<String>
pub async fn fetch_metadata(&self) -> Result<String>
Fetch $metadata XML
Retrieves the OData metadata document which describes the schema, entity types, properties, and relationships available in the API.
§Examples
let metadata = client.fetch_metadata().await?;
// Parse or save the XML metadata
println!("Metadata length: {} bytes", metadata.len());Sourcepub async fn execute_replication(
&self,
query: &ReplicationQuery,
) -> Result<ReplicationResponse>
pub async fn execute_replication( &self, query: &ReplicationQuery, ) -> Result<ReplicationResponse>
Execute a replication query
The replication endpoint is designed for bulk data transfer and supports
up to 2000 records per request. The response includes a next link in
the headers for pagination through large datasets.
§Important Notes
- Replication functionality requires MLS authorization
- Results are ordered oldest to newest by default
- Use
$selectto reduce payload size and improve performance - For datasets >10,000 records, replication is required
§Examples
let query = ReplicationQueryBuilder::new("Property")
.filter("StandardStatus eq 'Active'")
.select(&["ListingKey", "City", "ListPrice"])
.top(2000)
.build()?;
let response = client.execute_replication(&query).await?;
println!("Retrieved {} records", response.record_count);
// Continue with next link if more records available
if let Some(next_link) = response.next_link {
let next_response = client.execute_next_link(&next_link).await?;
}Sourcepub async fn execute_next_link(
&self,
next_link: &str,
) -> Result<ReplicationResponse>
pub async fn execute_next_link( &self, next_link: &str, ) -> Result<ReplicationResponse>
Execute a next link from a previous replication response
Takes the full URL from a previous replication response’s next_link
field and fetches the next batch of records.
§Examples
let query = ReplicationQueryBuilder::new("Property")
.top(2000)
.build()?;
let mut response = client.execute_replication(&query).await?;
let mut total_records = response.record_count;
// Continue fetching while next link is available
while let Some(next_link) = response.next_link {
response = client.execute_next_link(&next_link).await?;
total_records += response.record_count;
}
println!("Total records fetched: {}", total_records);