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 :
// 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
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs