I am attempting to retrieve data from the Zillow API using RapidApi. As a newcomer to NextJS, I'm exploring different ways to integrate APIs into my projects.
Below is the snippet of code found in my index.js:
export async function getStaticProps() {
const propertyForSale = await fetchApi(`${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-sale&hitsPerPage=6`)
const propertyForRent = await fetchApi(`${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-rent&hitsPerPage=6`)
return {
props: {
propertiesForSale: propertyForSale?.hits,
propertiesForRent: propertyForRent?.hits,
}
}
}
Additionally, here is the segment of code located within my fetchApi.js file:
export const baseUrl = 'https://zillow-com1.p.rapidapi.com'
export const fetchApi = async (url) => {
const { data } = await axios.get ((url), {
headers: {
'x-rapidapi-host': 'zillow-com1.p.rapidapi.com',
'x-rapidapi-key': '8e2e11ca6dmsh77a061b9b854a4ep1762d7jsne6e273637c9f'
}
})
return data;
}