#api-client #news #api #client #api-bindings #newsapi

thenewsapi

用于与 The News API 交互的客户端库,The News API 是一个免费服务,提供访问来自成千上万来源的全球新闻。

3 个版本

0.1.2 2024 年 7 月 19 日
0.1.1 2024 年 7 月 19 日
0.1.0 2024 年 7 月 19 日

#1764网络编程

Download history 261/week @ 2024-07-16 54/week @ 2024-07-23 18/week @ 2024-07-30

每月 333 次下载

MIT 许可证

19KB
249 代码行

The News API

The News API 的 Rust 客户端库,提供访问来自成千上万来源的全球新闻,具有卓越的响应时间。

特性

  • 按类别获取最新头条新闻
  • 检索顶级故事
  • 通过高级筛选访问所有新闻文章
  • 基于特定文章 UUID 查找类似新闻文章
  • 通过 UUID 检索特定文章
  • 列出可用的新闻来源

安装

将其添加到您的 Cargo.toml

[dependencies]
thenewsapi = "0.1.0"

确保您也具有所需的依赖项

[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"

用法

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),
    }
}

查看文档以了解所有支持的方法和参数。

许可证

本项目受 MIT 许可证的许可。有关详细信息,请参阅 LICENSE 文件。

贡献

欢迎贡献。请在 GitHub 上打开问题或提交拉取请求。

依赖项

~6–18MB
~254K SLoC