Spaces:
Sleeping
Sleeping
Download lib/services/api.ts from underrate/webdev-service: direct link, hf CLI and curl.
- Browser
- Download file 548 Bytes
-
https://huggingface.co/spaces/underrate/webdev-service/resolve/main/lib/services/api.ts
- Command line
-
hf download hf://spaces/underrate/webdev-service/lib/services/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/underrate/webdev-service/resolve/main/lib/services/api.ts
548 Bytes
| export const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000/api'; | |
| export async function fetchAPI(endpoint: string, options: RequestInit = {}) { | |
| const res = await fetch(`${API_URL}${endpoint}`, { | |
| ...options, | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| ...options.headers, | |
| }, | |
| }); | |
| if (!res.ok) { | |
| const error = await res.json().catch(() => ({})); | |
| throw new Error(error.error || 'An error occurred'); | |
| } | |
| return res.json(); | |
| } | |