Crate newswrap

source ·
Expand description

Hacker News API bindings for Rust with full async support.

use newswrap::{client::HackerNewsClient, errors::HackerNewsClientError};

#[tokio::main]
async fn main() -> Result<(), HackerNewsClientError> {
    // Build your client at the start of your application process
    let client = HackerNewsClient::new();

    // Call various endpoints with your client instance
    let generic_item = client.items.get_item(69).await?;
    dbg!(&generic_item);

    // Determine what the item type is
    let item_type = generic_item.get_item_type();
    dbg!(item_type);

    // Check if the item is job
    assert!(generic_item.is_story());

    // Retrieve user information
    let user = client.users.get_user("joeymckenzie").await?;
    dbg!(user);

    Ok(())
}

Modules

  • Hacker News API client bindings and various methods for interacting. The client is an async-first HTTP client and application authors should expect to bring an async runtime of their choosing. There are currently no plans to provide a blocking API, though this may change in future releases.
  • Various errors and their conversions for Hacker News API interactions.
  • Item response types associated to various Hacker News posts, comments, users, etc. Items are top level items in the Hacker News API and represent all stories, comments, polls, jobs, and poll options. Items contain a type identifying which entity they represent.
  • Data associated to the live data API endpoints pertaining to top stories, latest items, recently updated users, etc. Live data endpoints will vary in terms of their content and provide realtime insights into data captured by Hacker News.
  • User response models and various metadata about accounts and related objects.

Type Definitions

  • The ID associated to all Hacker News items and users.