MCPcopy
hub / github.com/adrianhajdin/project_next13_car_showcase / fetchCars

Function fetchCars

utils/index.ts:44–65  ·  view source on GitHub ↗
(filters: FilterProps)

Source from the content-addressed store, hash-verified

42};
43
44export 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
67export const generateCarImageUrl = (car: CarProps, angle?: string) => {
68 const url = new URL("https://cdn.imagin.studio/getimage");

Callers 1

HomeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected