#api-bindings #api-client #client

thenewsapi

A client library for interacting with The News API, a free service providing access to global news from thousands of sources

3 releases

0.1.2 Jul 19, 2024
0.1.1 Jul 19, 2024
0.1.0 Jul 19, 2024

#702 in #client

Download history 275/week @ 2024-07-19 54/week @ 2024-07-26 4/week @ 2024-08-02 16/week @ 2024-09-13 18/week @ 2024-09-20 32/week @ 2024-09-27 9/week @ 2024-10-04

75 downloads per month

MIT license

19KB
249 lines

The News API

A Rust client library for interacting with The News API (https://www.thenewsapi.com/), providing access to global news from thousands of sources with exceptional response times.

Features

  • Fetch latest headlines by category
  • Retrieve top stories
  • Access all news articles with advanced filtering
  • Find similar news articles based on a specific article UUID
  • Retrieve specific articles by UUID
  • List available news sources

Installation

Add this to your Cargo.toml:

[dependencies]
thenewsapi = "0.1.0"

Ensure you also have the required dependencies:

[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
anyhow = "1.0"

Usage

use thenewsapi::Client;

#[tokio::main]
async fn main() {
    let api_token = "your_api_token";
    let client = Client::new(api_token);

    // Example: Fetch latest headlines
    let params = HeadlinesParams::default();
    match client.get_headlines(params).await {
        Ok(headlines) => println!("{:?}", headlines),
        Err(e) => eprintln!("Error fetching headlines: {:?}", e),
    }
}

See the docs for all supported methods and parameters.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contribution

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

Dependencies

~6–20MB
~243K SLoC