JSON search endpoints and cURL

With a focus on cURL
Post Reply
KBleivik
Site Admin
Posts: 184
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway
Contact:

JSON search endpoints and cURL

Post by KBleivik »

A code example of how to make a call to a search endpoint and searching for a specific string.

Code: Select all

<?php
02	$apikey = 'insert_your_api_key_here';
03	$q = urlencode('Toy Story'); // make sure to url encode an query parameters
04	 
05	// construct the query with our apikey and the query we want to make
06	$endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $q;
07	 
08	// setup curl to make a call to the endpoint
09	$session = curl_init($endpoint);
10	 
11	// indicates that we want the response back
12	curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
13	 
14	// exec curl and get the data back
15	$data = curl_exec($session);
16	 
17	// remember to close the curl session once we are finished retrieveing the data
18	curl_close($session);
19	 
20	// decode the json data to make it easier to parse the php
21	$search_results = json_decode($data);
22	if ($search_results === NULL) die('Error parsing json');
23	 
24	// play with the data!
25	$movies = $search_results->movies;
26	echo '<ul>';
27	foreach ($movies as $movie) {
28	  echo '<li><a href="' . $movie->links->alternate . '">' . $movie->title . " (" . $movie->year . ")</a></li>";
29	}
30	echo '</ul>';
31	 
32	 
33	?>
Source: http://developer.rottentomatoes.com/doc ... 0/examples

Related links:
How to expose a JSON endpoint from a WCF-service

Having seen the small footprint set by JSON – I’ve begun using it extensively for mobile device (WP7) communication. In particular the phone scenario makes it desirable to have an as small as possible data load to transfer between server and device. When using the JSON formatting, you can really minimize the load as documented here
Source: http://blog.clauskonrad.net/2010/11/how ... m-wcf.html

End point security:
http://www.endpoint.no/

http://www.jsontest.com/

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest