Rotten Tomatoes API Exercise
Objective
In this exercise you will learn how to use an external API to display contextually relevant data
Preparation
- Read Chapter 8 of The Live Web.
- The Rotten Tomatoes API documentation is here:
- Create an account with Mashery, if necessary (click the Register link at the top of the API docs)
- Obtain an API key for Rotten Tomatoes (should be issued automatically if you created a new account)
Exercise
- Create a
rotten_tomatoes
ruleset and register it using KDK. - Define a function in the
global
block of the ruleset that useshttp:get()
to interact with themovies.json
endpoint of the Rotten Tomatoes API. Be sure to include your API key as the first argument of the query string. Note that if you can't retrieve the data usingcurl
or a browser, your function won't be able to either. - Use the techniques from Web Rule Exercises and the (Classic) Quickstart for SquareTag, build a SquareTag app that displays a form that asks the user for a movie title.
- The rule that responds to the
web:submit
event should extract the movie title from the the form data and query the Rotten Tomatoes datasource with the movie title and retrieve the desired information (e.g., critic and audience ratings) from the JSON response using thepick()
operator. - The rule should then display the following information on SquareTag:
- Movie thumbnail
- Title
- Release Year
- Synopsis
- Critic ratings
- and other data you find interesting.
- The data should be nicely formatted and allow the user to type another movie title in at the bottom.
- If the movie isn't found, display a nice error message that returns the title the user put in.
Notes
- You should only create the panel on SquareTag once and then modify it's contents as necessary. This is a version of the initialize then populate pattern
Copyright Picolabs | Licensed under Creative Commons.