Skip to main content

Crate newsapi_rust

Crate newsapi_rust 

Source
Expand description

§newsapi-rust

A robust, async Rust client for the NewsAPI.org news aggregator API.

This library provides a type-safe, async interface to all NewsAPI v2 endpoints:

  • /top-headlines - get breaking news headlines
  • /everything - search millions of articles
  • /sources - discover available news sources

§Quick Start

Add to your Cargo.toml

[dependencies]
newsapi-rust = "0.1"
tokio = { version = "1.0", features = ["full"] }

Then:

use newsapi_rust::{NewsApiClient, ApiVersion};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client =  NewsApiClient::new("YOUR_API_KEY", ApiVersion::V2);
    let params = TopHeadlinesParams::new()
        .country("us")
       .category("technology");
    let response = client.top_headlines(&params).await?;
    for article in response.articles {
       println!("{} - {}", article.title, article.url);
    }
    Ok(())
}

Structs§

Article
Represents a news article returned by the API.
EverythingParams
Parameters for the /everything endpoint.
NewsApiClient
The main NewsAPI client.
Source
Represents the source of a news article, containing its ID and name.
SourceParams
Parameters for the /sources endpoint.
SuccessResponse
Represents a successful response from the API, containing the total number of results and a list of articles.
TopHeadlinesParams
Parameters for the /top-headlines endpoint.

Enums§

ApiVersion
API version enum for NewsAPI. Currently only supports v2, but designed for future extensibility.
NewsApiError
The main error type for the News API client library.

Type Aliases§

Result
A specialized Result type for the News API client library.