1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

First commit

Public timeline working, with refreshing and load more
This commit is contained in:
Zhiyuan Zheng
2020-10-22 00:47:02 +02:00
parent fb152fece9
commit 4af19d0588
10 changed files with 587 additions and 22 deletions

21
api/client.js Normal file
View File

@ -0,0 +1,21 @@
export async function client(endpoint, { body, ...customConfig } = {}) {
let data
try {
const response = await window.fetch(endpoint, config)
data = await response.json()
if (response.ok) {
return data
}
throw new Error(response.statusText)
} catch (err) {
return Promise.reject(err.message ? err.message : data)
}
}
client.get = function (endpoint, customConfig = {}) {
return client(endpoint, { ...customConfig, method: 'GET' })
}
client.post = function (endpoint, body, customConfig = {}) {
return client(endpoint, { ...customConfig, body })
}