Skip to content

saberstack/clj-hackernews-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HackerNews API Client

A Clojure client library for the Official HackerNews API built using babashka.http-client.

Overview

This library provides a simple interface to interact with the HackerNews Firebase API, allowing you to retrieve stories, comments, user information, and other data from HackerNews.

Installation

Add the following dependency to your deps.edn:

org.saberstack/clj-hackernews-api {:git/sha "lookup latest sha"}

API Reference

All functions return HTTP response maps from babashka.http-client/get.

Items

item!

Retrieves any item (story, comment, poll, etc.) by its ID.

(item! 42)

Parameters:

  • id - The item's unique ID

Users

user!

Retrieves user information by username.

(user! "raspasov")

Parameters:

  • username - The user's username (case-sensitive)

Note: Usernames are case-sensitive.

Stories

new-stories!

Returns up to 500 new stories.

(new-stories!)

top-stories!

Returns up to 500 top stories.

(top-stories!)

best-stories!

Returns up to 500 best stories.

(best-stories!)

ask-stories!

Returns up to 200 Ask HN stories.

(ask-stories!)

show-stories!

Returns up to 200 Show HN stories.

(show-stories!)

job-stories!

Returns up to 200 job stories.

(job-stories!)

Metadata

max-item!

Returns the current largest item ID.

(max-item!)

updates!

Returns recent item and profile changes.

(updates!)

Usage Examples

(ns my.app
  (:require [org.saberstack.hn.api-v0 :as hn]))

;; Get a specific item
(hn/item! 42)

;; Get user information
(hn/user! "pg")

;; Get top stories
(hn/top-stories!)

;; Get the highest item ID
(hn/max-item!)

Response Format

All functions return HTTP response maps with the following structure:

{:status 200
 :headers {...}
 :body "..."}  ; body is a string containing JSON

The actual HackerNews data will be in the :body key of the response.

API Endpoints

This library wraps the following HackerNews API endpoints:

  • https://hacker-news.firebaseio.com/v0/item/{id}.json
  • https://hacker-news.firebaseio.com/v0/user/{username}.json
  • https://hacker-news.firebaseio.com/v0/maxitem.json
  • https://hacker-news.firebaseio.com/v0/updates.json
  • https://hacker-news.firebaseio.com/v0/topstories.json
  • https://hacker-news.firebaseio.com/v0/newstories.json
  • https://hacker-news.firebaseio.com/v0/beststories.json
  • https://hacker-news.firebaseio.com/v0/askstories.json
  • https://hacker-news.firebaseio.com/v0/showstories.json
  • https://hacker-news.firebaseio.com/v0/jobstories.json

For detailed information about the API and response formats, refer to the Official HackerNews API documentation.

About

Clojure client library for the HackerNews API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published