Wikipedia search summary API

After Random images from wikipedia I made another simple API to get the summary for a search term using PHP.

It's a JSONP API that queries the DNS of wikipedia to fetch the TXT records, which also includes a short URL to the complete corresponding Wikipedia entry. As cross-domain requests are possible with this API, one can easily integrate it to search boxes or widgets.

Monkey code :

<?php

// Set headers for JSON
header('Content-type: application/json');

// This the DNS to query  
$DNS=$_GET['q'].".wp.dg.cx";

// Get the TXT records for the Name server
$result = dns_get_record($DNS,DNS_TXT);

// Return the JSONP
print $_GET['callback'].'('.json_encode(array("res"=>$result[0]['txt'])).')';

?>
 

<

p>A simple $.getJSON() can be used to get the data.res
indeed the famous "callback=?" trick is <3'd by one and all.

SAMPLE RESPONSE with callback=?

You might also like One line GUI wikipedia search

Share this