This commit is contained in:
john 2025-05-03 20:18:08 +02:00
parent 2586dc87c8
commit e84cf232a5
13 changed files with 605 additions and 139 deletions

26
src/api/api.ts Normal file
View 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()
}