| 42 | }; |
| 43 | |
| 44 | export async function fetchCars(filters: FilterProps) { |
| 45 | const { manufacturer, year, model, limit, fuel } = filters; |
| 46 | |
| 47 | // Set the required headers for the API request |
| 48 | const headers: HeadersInit = { |
| 49 | "X-RapidAPI-Key": process.env.NEXT_PUBLIC_RAPID_API_KEY || "", |
| 50 | "X-RapidAPI-Host": "cars-by-api-ninjas.p.rapidapi.com", |
| 51 | }; |
| 52 | |
| 53 | // Set the required headers for the API request |
| 54 | const response = await fetch( |
| 55 | `https://cars-by-api-ninjas.p.rapidapi.com/v1/cars?make=${manufacturer}&year=${year}&model=${model}&limit=${limit}&fuel_type=${fuel}`, |
| 56 | { |
| 57 | headers: headers, |
| 58 | } |
| 59 | ); |
| 60 | |
| 61 | // Parse the response as JSON |
| 62 | const result = await response.json(); |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | export const generateCarImageUrl = (car: CarProps, angle?: string) => { |
| 68 | const url = new URL("https://cdn.imagin.studio/getimage"); |