parse_url

Function parse_url 

Source
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 fetch
  • etag - Optional ETag from previous fetch for conditional GET
  • modified - Optional Last-Modified timestamp from previous fetch
  • user_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 redirects
  • etag: ETag header value (for next request)
  • modified: Last-Modified header 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");
}