Rotten Tomatoes API
This tutorial shows how to configure a remote web service to connect to the Rotten Tomatoes API. It shows how to pass parameters like API key to the remote service.
Create the Remote Web Service
- In the admin console, go to the Services tab and click Create.
- Set the Service Type to 'Remote Service' > 'HTTP Service'.
- Set the service name to 'rotten'.
- Set the service label to 'Rotten Tomatoes API'. Check the Active checkbox.
- Go to the Config tab for the new service and set the Base URL to http://api.rottentomatoes.com/api/public/v1.0/.
- Click the '+' button under Parameters to add a new parameter.
- Set the name to 'apikey' and the value to your API key issued from the Rotten Tomatoes developer portal.
- Check the 'Outbound' checkbox so that your DreamFactory instance will pass the parameter through to the Rotten Tomatoes API.
- Select all verbs so that the parameter is sent to the Rotten Tomatoes API for all requests.
- Click Create Service to save your new service.
Call the Remote Web Service
You can now use any REST client to access your remote web service using the DreamFactory REST API. See other tutorials for authentication options. To get a list of movies in theaters you would send the following request. Replace http://localhost:8080 with the URL for your DreamFactory instance.
GET http://localhost:8080/api/v2/rotten/lists/movies/in_theaters.json?page_limit=1&page=1&country=us
For example, with cURL you can first log in as a DreamFactory admin and get a session token:
curl -i -k -3 -X POST "http://localhost:8080/api/v2/system/admin/session" -d '{ "email" : "[email protected]", "password" : "your_password" }' -H "Content-Type: application/json"
Then make a cURL call to the Rotten Tomatoes API, like this:
curl -i -k -3 -X GET "http://localhost:8080/api/v2/rotten/lists/movies/in_theaters.json?page_limit=1&page=1&country=us" -H "X-DreamFactory-Api-Key: <api key for the admin app in the apps tab>" -H "X-DreamFactory-Session-Token: <session token returned by the login api call above>"
DreamFactory combines the request URL from the client with the configured base URL for the service to generate the actual URL for the request. Everything after the service name, 'rotten' in this case, is appended to the base URL to generate the final URL.
GET http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=1&page=1&country=us&apikey=xxxxxxxxxxxxx
DreamFactory also appends the apikey parameter before sending the request on to the Rotten Tomatoes API. This ensures that your API key or other sensitive information is never exposed to the client app. The response will be in JSON format.
{ "total": 138, "movies": [ { "id": "770807799", "title": "Goosebumps", "year": 2015, "mpaa_rating": "PG", "runtime": 103, "critics_consensus": "", "release_dates": { "theater": "2015-10-16" }, "ratings": { "critics_rating": "Fresh", "critics_score": 73, "audience_rating": "Upright", "audience_score": 74 }, "synopsis": "Upset about moving from a big city to a small town, teenager Zach Cooper (Dylan Minnette) finds a silver lining when he meets the beautiful girl, Hannah (Odeya Rush), living right next door. But every silver lining has a cloud, and Zach's comes when he learns that Hannah has a mysterious dad who is revealed to be R. L. Stine (Jack Black), the author of the bestselling Goosebumps series. It turns out that there is a reason why Stine is so strange... he is a prisoner of his own imagination - the monsters that his books made famous are real, and Stine protects his readers by keeping them locked up in their books. When Zach unintentionally unleashes the monsters from their manuscripts and they begin to terrorize the town, it's suddenly up to Stine, Zach, and Hannah to get all of them back in the books where they belong. Note: Scholastic has sold over 400 million Goosebumps books worldwide in 32 languages since the series introduction in 1992, earning critical acclaim and dominating global best seller lists. R.L. Stine has been recognized as one of the bestselling children's authors in history. (c) Sony", "posters": { "thumbnail": "http://resizing.flixster.com/s6Z8WRS8z94QTJil3axVPx3NFoM=/54x72/dkpu1ddg7pbsk.cloudfront.net/movie/11/19/31/11193185_ori.jpg", "profile": "http://resizing.flixster.com/s6Z8WRS8z94QTJil3axVPx3NFoM=/54x72/dkpu1ddg7pbsk.cloudfront.net/movie/11/19/31/11193185_ori.jpg", "detailed": "http://resizing.flixster.com/s6Z8WRS8z94QTJil3axVPx3NFoM=/54x72/dkpu1ddg7pbsk.cloudfront.net/movie/11/19/31/11193185_ori.jpg", "original": "http://resizing.flixster.com/s6Z8WRS8z94QTJil3axVPx3NFoM=/54x72/dkpu1ddg7pbsk.cloudfront.net/movie/11/19/31/11193185_ori.jpg" }, "abridged_cast": [ { "name": "Jack Black", "id": "162662218", "characters": [ "R.L. Stine" ] }, { "name": "Dylan Minnette", "id": "770808601", "characters": [ "Zach Cooper" ] }, { "name": "Odeya Rush", "id": "771377595", "characters": [ "Hannah" ] }, { "name": "Amy Ryan", "id": "162653858", "characters": [ "Gale" ] }, { "name": "Jillian Bell", "id": "771103724", "characters": [ "Lorraine" ] } ], "alternate_ids": { "imdb": "1051904" }, "links": { "self": "http://api.rottentomatoes.com/api/public/v1.0/movies/770807799.json", "alternate": "http://www.rottentomatoes.com/m/goosebumps_2015/", "cast": "http://api.rottentomatoes.com/api/public/v1.0/movies/770807799/cast.json", "reviews": "http://api.rottentomatoes.com/api/public/v1.0/movies/770807799/reviews.json", "similar": "http://api.rottentomatoes.com/api/public/v1.0/movies/770807799/similar.json" } } ], "links": { "self": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=1&country=us&page=1", "next": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=1&country=us&page=2", "alternate": "http://www.rottentomatoes.com/movie/in_theaters" }, "link_template": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit={results_per_page}&page={page_number}&country={country-code}" }
The result is returned back to the client. You also have the option to create server-side scripts to manipulate the request or response.