pub fn parse_url(
url: &str,
etag: Option<&str>,
modified: Option<&str>,
user_agent: Option<&str>,
) -> Result<ParsedFeed>Expand description
Parse feed from HTTP/HTTPS URL
Fetches the feed from the given URL and parses it. Supports conditional GET
using ETag and Last-Modified headers for bandwidth-efficient caching.
§Arguments
url- HTTP or HTTPS URL to fetchetag- OptionalETagfrom previous fetch for conditional GETmodified- OptionalLast-Modifiedtimestamp from previous fetchuser_agent- Optional custom User-Agent header
§Returns
Returns a ParsedFeed with HTTP metadata fields populated:
status: HTTP status code (200, 304, etc.)href: Final URL after redirectsetag:ETagheader value (for next request)modified:Last-Modifiedheader value (for next request)headers: Full HTTP response headers
On 304 Not Modified, returns a feed with empty entries but status=304.
§Errors
Returns FeedError::Http if:
- Network error occurs
- URL is invalid
- HTTP status is 4xx or 5xx (except 304)
§Examples
use feedparser_rs::parse_url;
// First fetch
let feed = parse_url("https://example.com/feed.xml", None, None, None).unwrap();
println!("Title: {:?}", feed.feed.title);
println!("ETag: {:?}", feed.etag);
// Subsequent fetch with caching
let feed2 = parse_url(
"https://example.com/feed.xml",
feed.etag.as_deref(),
feed.modified.as_deref(),
None
).unwrap();
if feed2.status == Some(304) {
println!("Feed not modified, use cached version");
}