23 lines
497 B
TypeScript
23 lines
497 B
TypeScript
const API_BASE_URL = '/api/v1'
|
|
|
|
export interface ApiResponse<T = unknown> {
|
|
code: number
|
|
msg: string
|
|
payload: T | null
|
|
}
|
|
|
|
export interface DemoResponse {
|
|
sleep_time_ms: number
|
|
}
|
|
|
|
export function callDemoApi(): Promise<ApiResponse<DemoResponse>> {
|
|
return fetch(`${API_BASE_URL}/demo`)
|
|
.then((response) => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`)
|
|
}
|
|
return response.json() as Promise<ApiResponse<DemoResponse>>
|
|
})
|
|
}
|
|
|