type Abstractapi = {
apiKey: string
}
export async function main(
resource: Abstractapi,
countryCode: string,
filter?: {
year?: number
month?: number
day?: number
}
) {
const queryParams = new URLSearchParams({
api_key: resource.apiKey,
country: countryCode
})
if (filter?.year) {
queryParams.append('year', filter.year.toString())
}
if (filter?.month) {
queryParams.append('month', filter.month.toString())
}
if (filter?.day) {
queryParams.append('day', filter.day.toString())
}
const endpoint = `https://holidays.abstractapi.com/v1?${queryParams.toString()}`
const response = await fetch(endpoint, {
method: 'GET'
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 72 days ago