export type CreateApiPagesArgs = {body: BodyInit}; export type CreateApiPagesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an entry * * POST /pages */ export const createApiPages = async (args: CreateApiPagesArgs, options?: CreateApiPagesOptions) => { const {baseUrl = "https://www.rcac.purdue.edu/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "*/*") const url = `${baseUrl.replace(/\/+$/, '')}/pages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };