File size: 615 Bytes
7232589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const API_BASE = '/api/v1'

export async function fetchStatus() {
  const r = await fetch(`${API_BASE}/status`)
  return r.json()
}

export async function fetchPosts(params = {}) {
  const q = new URLSearchParams()
  if (params.category) q.set('category', params.category)
  if (params.topic) q.set('topic', params.topic)
  if (params.limit) q.set('limit', params.limit)
  if (params.min_score) q.set('min_score', params.min_score)
  const r = await fetch(`${API_BASE}/posts?${q}`)
  return r.json()
}

export async function fetchCategories() {
  const r = await fetch(`${API_BASE}/categories`)
  return r.json()
}