do feed
This commit is contained in:
parent
2586dc87c8
commit
e84cf232a5
13 changed files with 605 additions and 139 deletions
26
src/api/api.ts
Normal file
26
src/api/api.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { components } from './schema.ts'
|
||||
|
||||
// TODO for now we just assume that the API and client are running on the same host
|
||||
// i think this might change but dependes on what we do with deployment
|
||||
const ApiHost = `http://${location.hostname}:5181`
|
||||
|
||||
console.debug('API HOST IS', ApiHost)
|
||||
|
||||
export async function loadPostsForAuthor(
|
||||
authorId: string,
|
||||
count?: number,
|
||||
cursor?: string,
|
||||
): Promise<components['schemas']['GetAuthorPostsResponse']> {
|
||||
const url = new URL(`authors/${authorId}/posts`, ApiHost)
|
||||
if (count != null) url.searchParams.set('count', count.toString())
|
||||
|
||||
if (cursor) url.searchParams.set('cursor', cursor)
|
||||
|
||||
const request = new Request(url)
|
||||
|
||||
const response = await fetch(request)
|
||||
|
||||
if (!response.ok) throw new Error(await response.text())
|
||||
|
||||
return await response.json()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue