Spaces:
Running
Running
Download frontend/src/shared/api/http.ts from Pier-Jean/docling-studio: direct link, hf CLI and curl.
- Browser
- Download file 587 Bytes
-
https://huggingface.co/spaces/Pier-Jean/docling-studio/resolve/main/frontend/src/shared/api/http.ts
- Command line
-
hf download hf://spaces/Pier-Jean/docling-studio/frontend/src/shared/api/http.ts
-
curl -L -o http.ts https://huggingface.co/spaces/Pier-Jean/docling-studio/resolve/main/frontend/src/shared/api/http.ts
587 Bytes
| interface FetchOptions extends RequestInit { | |
| skipContentType?: boolean | |
| } | |
| export async function apiFetch<T = unknown>(url: string, options: FetchOptions = {}): Promise<T> { | |
| const headers: Record<string, string> = { ...(options.headers as Record<string, string>) } | |
| if (!options.skipContentType) { | |
| headers['Content-Type'] = 'application/json' | |
| } | |
| const response = await fetch(url, { | |
| ...options, | |
| headers, | |
| }) | |
| if (!response.ok) throw new Error(`API error: ${response.status}`) | |
| if (response.status === 204) return null as T | |
| return response.json() as Promise<T> | |
| } | |