17 lines
411 B
TypeScript
17 lines
411 B
TypeScript
export interface CommuneData {
|
|
nom: string
|
|
code: string
|
|
}
|
|
|
|
export async function getCommunesByPostalCode(postalCode: string): Promise<CommuneData[]> {
|
|
const config = useRuntimeConfig()
|
|
const base = config.public.geoApiBase
|
|
try {
|
|
return await $fetch<CommuneData[]>(`${base}/communes`, {
|
|
params: { codePostal: postalCode, fields: 'nom', format: 'json' }
|
|
})
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|