Demo Application
Learn how TMDB APIs can be integrated into a real-world application.
We'll cover the following
We gained hands-on experience with The Movie Database API endpoints in the previous chapters. Now, we’ll integrate those endpoints into a real-world application.
Workflow
- When we run the application, the first page we see is the home page. The home page has two main components using the API endpoints—the navigation bar, and flashcards.
- For flashcards, by hovering over them, we can see some basic details of a movie or a TV show. When we click “View Details,” it takes us to the movie or the TV show details page.
- The various options shown in the navigation bar (to the left side of the webpage) are discussed below:
- “MovieTV” or “Home” take us to the home page if we are not already there.
- “Movies” takes us to the movies page, where we can see the latest, trending, popular, top-rated, upcoming, and currently playing movies.
- “TV Shows” takes us to the TV page, where we can see the latest, trending, popular, top-rated, airing today, and on the air TV Shows.
- “People” takes us to the persons page, where we can see all the popular persons on TMDB.
- For the navigation bar (right side), we have to select the object to be searched, movie, TV show, or person, then we type in our query in the search bar and finally click the search button or press enter. This takes us to the results page.
API endpoints in use
We have used endpoints in the views.py
file.
-
The
index
function in line 10 uses the trending endpoint in line 11. The value ofmedia_type
is set toall
and the value oftime_window
is set today
. We use this function to display the trending movies and TV shows on the home page. -
The
search
function in line 16 uses the search endpoint in line 22. It takes the media type (movie or TV) and query string from the user and returns the search results. We useinclude_adult=false
to filter the adult content from the results. -
The
movies
function in line 33 is used to display the “Movies” page. It uses multiple endpoints, like the latest movie endpoint in line 34, trending movies in line 35, popular movies in line 36, top movies in line 37, upcoming movies in line 38, and now playing movies in line 39, to display the sets of all these movies. -
The
tv
function in line 50 is used to display the “TV Shows” page. It uses multiple endpoints, like the endpoint for latest TV shows in line 51, trending TV shows in line 52, popular TV shows in line 53, top TV shows in line 54, the endpoint for TV shows airing today in line 55 and on air TV shows in line 56, to display the sets of all these TV shows. -
The
movie_detail
function in line 67 is used to display the details for the selected movie. The function uses the following endpoints:- The primary movie details endpoint in line 68 is used to fetch and display all the basic details about the requested movie.
- The recommendations endpoint in line 69 is used to fetch and display a list of recommended movies for the requested movie.
- The credits endpoint in line 70 is used to fetch and display all the cast and crew of the requested movie.
- The videos endpoint in line 71 to fetch and display all the videos of the requested movie.
-
The
tv_detail
function in line 81 is used to display the details for the selected TV show. The function uses the following endpoints:- The primary tv details endpoint in line 82 is used to fetch and display all the basic details about the requested TV show.
- The recommendations endpoint in line 83 is used to fetch and display a list of recommended TV shows for the requested TV show.
- The credits endpoint in line 84 is used to fetch and display all the cast and crew of the requested TV show.
- The videos endpoint in line 85 is used to fetch and display all the videos of the requested TV show.
-
The
season_detail
function in line 95 is used to display the details for the requested season of a TV show. It uses the season endpoint in line 96 that needsseason_number
to specify which season to return. -
The
episode_detail
function in line 103 is used to display the details for the requested episode of a TV show. It uses the episode endpoint in line 104 that needsepisode_number
along withseason_number
to specify which episode to return. -
The
people_detail
function in line 110 is used to display the details for the requested person. It uses the person endpoint in line 111 that takesperson_id
as the required parameter. The function also uses thecombined_credits
endpoint with theperson_id
as the required parameter. -
The
people
function in line 117 is used to display all the popular persons on TMDB. It uses the popular endpoint in line 118 to fetch and display all the popular persons.
Note: The following widget only shows the necessary files required to explain The Movie Database APIs.
Click “Run” to run the application. Next, click on the URL given at the end of the widget to watch the application up and running.
Get hands-on with 1400+ tech skills courses.