Week 6 Homework

IMDB – the Internet Movie Database (owned by Amazon) – famously does not provide an API to access data about the millions of movies and TV shows indexed on their website. That doesn't mean there can't be one! It's up to you to create it.

Getting Started

Begin by heading over to the starter project – select "Use this template", then create a repository in your own GitHub account called hw6. Clone this project and open it in VSCode.

Open a VSCode Terminal and (making sure you're in the right project directory) type npm install – don't skip this step! – this will install all the necessary software needed to run the back-end application. Then, type netlify dev to start the back-end server.

Open /.netlify/functions/movies in Chrome. Nothing there yet! Then, open the code for the lambda function, located in /netlify/functions/movies.js and get coding!

The Goal

While IMDB does not have a live, open API for developers, they do provide file-based downloads to their raw data. A sample of that data has been downloaded and provided at movies.csv. The code for reading that data into a JavaScript object has also already been provided. Your job is to create a JSON-based API for front-end JavaScript developers to use.

Rubric

  1. (1 points) Write the recipe (algorithm) for your approach in the comments. Do this first!
  2. (4 points) Require the developer using your API to pass two querystring parameters – one for the year the movie was released (the startYear) and another for the genre. For example: http://localhost:8888/.netlify/functions/movies?year=2018&genre=Comedy. Only provide results for the given year and genre. Hint: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes. If these two parameters are not provided, return a simple String with an error message. Hint hint: if a variable doesn't exist, it equals undefined.
  3. (3 points) The resulting JSON should be an Object, which includes two key-value pairs – numResults and movies. The value of numResults should be the total number of movies returned, and the value of movies should be an Array of Objects containing the following details on each movie:
    • The primary title of the movie
    • The year the movie was released
    • The movie's genres
  4. (2 points) Ignore any results with no genre – i.e. when the genres is \\N or movies with no runtime – when runtimeMinutes is \\N.

Guidelines for Submission

All your work should take place in /netlify/functions/movies.js; i.e. that should be the only file that's modified from the original project template. Your finished product should live in your GitHub account at https://github.com/<your GitHub username>/hw6, and this URL should be submitted as the "website URL" for this assignment in Canvas.