I'm new to fastify and nodejs I would like to create a route, allowing me to retrieve the information of the top 1 film thanks to the themoviedb API
First, I have to get the first movie that sends back the road 'https://api.themoviedb.org/3/discover/movie " then retrieve the film information using the movie / id route of themoviedb
I tried to do this
import fastify from 'fastify';
import dotenv from 'dotenv'
dotenv.config();
import got from 'got';
const app = fastify();
app.get('/movies/top1', async (request, reply) => {
let response;
try {
response = await got('https://api.themoviedb.org/3/discover/movie?api_key='+process.env.API_KEY+'&sort_by=vote_average.asc');
} catch (err) {
console.log(err)
}
let responseMovie;
try {
responseMovie = await got('https://api.themoviedb.org/3/movie/'+ response.body.results[0].id +'?api_key='+process.env.API_KEY);
} catch (err) {
console.log(err)
}
reply.send(responseMovie.body);
});
app.listen(8000);
But I have an error "Cannot read properties of undefined (reading '0')" I would like to execute the second request when the first is finished and return the result of the second request HOw to do this please ?