01.[Hacker_News] Hacker News API

장일규·2022년 1월 11일

Hacker_News

목록 보기
1/2

Design

The v0 API is essentially a dump of our in-memory data structures. We know, what works great locally in memory isn't so hot over the network. Many of the awkward things are just the way HN works internally. Want to know the total number of comments on an article? Traverse the tree and count. Want to know the children of an item? Load the item and get their IDs, then load them. The newest page? Starts at item maxid and walks backward, keeping only the top level stories. Same for Ask, Show, etc.

I'm not saying this to defend it - It's not the ideal public API, but it's the one we could release in the time we had. While awkward, it's possible to implement most of HN using it.

해커뉴스 API Design에 대한 안내이다.

대충 영어를 해석하여 보면 어색한 부분이 있음, 각, Item에 대한 세부 정보를 알고 싶으면 ID를 받아서 API콜을 해야함

어색하지만, 대부분의 HN을 구현할 수 있음..

topstories.json

https://hacker-news.firebaseio.com/v0//topstories.json

위에 API를 call하면 상위(top) 500개의 Hacker News의 ID를 조회할 수 있다.

API를 call했을 시 500개(대괄호[] 요거 두개 빼고)의 ID가 조회되는 것을 확인 할 수 있다.

띠용??

내가 생각했던 json형태는 ID를 포함하여 제목,게시일, url 등등이 포함되어 있어야한다고 생각했는데.. Design에서 설명 하였듯이 어색한 부분이 있기에 이런 식으로 api콜이 진행되면 List에 뿌려줄때와, Detail에 뿌려줄 때 어떤 식으로 해야할까? 흥미가 생셔서 진행하게 됨..

/item/{item-id}.json

{item-id}에 30223402를 바인딩 했을 때 정보들이다.

objecttypedescisRequired
idintegerThe item's unique id.(항목의 고유 ID)required
deletedbooleantrue if the item is deleted.(항목이 삭제되면 true)optional
typestringThe type of item. One of "job", "story", "comment","poll", or "pollopt".(항목 유형)required
bystringThe username of the item's author. (항목 저자)optional
timeintegerCreation date of the item, in Unix Time. (항목을 만든 날짜)optional
deadbooleantrue if the item is dead. ()optional
kidsarray[integer]The ids of the item's comments, in ranked display order.항목 설명 ID(순위 표시 순서)서)optional
parentintegerThe item's parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll.(항목의 부모 )optional
textstringThe comment, story or poll text. HTML.(텍스트)optional

0개의 댓글