export type CreateApiQuoteArgs = {quote: unknown, author?: unknown | undefined, tags?: unknown | undefined, language?: unknown | undefined}; export type CreateApiQuoteOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add a new quote to your private collection. Same as 'PUT' but added since some clients don't handle PUT well. * * POST /quote */ export const createApiQuote = async (args: CreateApiQuoteArgs, options?: CreateApiQuoteOptions) => { const {baseUrl = "https://quotes.rest", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.quote != null) query.append("quote", String(args.quote)) if (args.author != null) query.append("author", String(args.author)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.language != null) query.append("language", String(args.language)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/quote${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };