0.1.1 • Published 5 years ago
hn-api-client v0.1.1
hn-api-client
A isomorphic api client for Hacker News API
Installation
yarn i hn-api-client
ornpm i hn-api-client
Usage
const hnApiClient = require('hn-api-client')
.getItem(id)
await hnApiClient.getItem(8863);
/*{
by: 'dhouston',
descendants: 71,
id: 8863,
kids: [...],
title: 'My YC app: Dropbox - Throw away your USB drive',
type: 'story',
...
}*/
.getUser(id)
await hnApiClient.getUser('Malfunction92');
/*{
created: 1451669897,
id: 'Malfunction92',
karma: 34,
submitted: [ 10867439, 10822491, ... ]
}*/
.getMaxItemID(id)
await hnApiClient.getMaxItemID();
/*18920326*/
.getTopStories()
await hnApiClient.getTopStories();
/*[
{by: 'dankohn1', id: 18912321, kids: [18920127, 18919744, ...], score: 179, ... },
{by: 'vbezhenar', id: 18919543, kids: [18920212, 18919663, ...], score: 22, ... },
...
]*/
/* To get only ids of stories: */
await hnApiClient.getTopStories({onlyIds: true});
/*[
18912321,
18919543]
*/
You can use the following similar methods
await hnApi.getNewStories()
await hnApi.getBestStories()
await hnApi.getAskStories()
await hnApi.getShowStories()
await hnApi.getJobStories()
.getUpdates()
await hnApiClient.getUpdates();
/* {
items: [18919919, 18916487, 18920263, ...],
users: ["blopeur", "sascha_sl", "doppp", ...]
*/