Client minimal en TypeScript
const BASE_URL = process.env.TS_IMMO_API_URL ?? 'https://api.ts-immo.org'
const API_KEY = process.env.TS_IMMO_API_KEY!
export async function tsImmoFetch<T>(path: string): Promise<T> {
const res = await fetch(`${BASE_URL}${path}`, {
headers: { Authorization: `Bearer ${API_KEY}` },
})
if (!res.ok) {
const err = await res.json().catch(() => ({}))
throw new Error(`Ts-Immo ${res.status} ${err.code ?? ''}: ${err.message ?? path}`)
}
return res.json() as Promise<T>
}Exemple Express (endpoint public mono-agence)
import { Router } from 'express'
import { tsImmoFetch } from '../lib/ts-immo'
export const biensRouter = Router()
biensRouter.get('/agence/:agencySlug', async (req, res) => {
const list = await tsImmoFetch(
`/v1/gateway/public/properties/${req.params.agencySlug}`
)
res.json(list)
})