
Wikipedia recently introduced a new auto-complete search feature that offers keyword suggestions in real-time as you type the characters in the Wikipedia search box.
For instance, if you type "GOO", the drop down will show titles of all Wikipedia entries that begin with the word "GOO" (see screenshot).
This Google Suggest like feature is actually built on an undocumented but public Wikipedia API that can easily be used to retrieve useful information from the Wikipedia database. To demonstrate the use of Wikipedia API, here is a simple Wikipedia spell checker app:
The above spell checker fires an Wikipedia API query to see if Wikipedia has an entry about the word you just entered in the search box and says "Correct" if it finds one.
For the geeks, here’s the actual source code:
var url = ‘http://en.wikipedia.org/w/api.php?action=opensearch&search=value&format=json&callback=spellcheck‘;
var elem = document.createElement (’script’);
elem.setAttribute (’src’, url);
elem.setAttribute (‘type’,'text/javascript’);
document.getElementsByTagName (‘head’) [0].appendChild (elem);
A related example – if you want to know about Wikipedia articles that begin with the term "India", just the following URL in your web browser:
http://en.wikipedia.org/w/api.php?action=opensearch&search=india
The above Wikipedia URL would return the following set of words:
["india",["India","INDIA","India (album)","India (cat)","India (disambiguation)","India (name)","India (porn star)","India (region)","India (singer)","India (subcontinent)"]]
So what else could one do with the Wikipedia API ? Here are some more uses:
1. A Wordpress plugin which auto links terms to Wikipedia articles.
2. A "better" Wikipedia search which hooks up Google "Did you mean" with the Wikipedia API, so that misspellings also direct to the correct article.
3. A Firefox extension which allows single click querying of terms.
The Wikipedia API was dissected by Pratham who maintains a very interesting tumbleblog at pratham.name and tweets here. Note that this not an official API (Wikipedia is not talking about this yet), therefore use on a production system is not advised.
Related: Track Changes To Your Favorite Wikipedia Articles
Find this article at: http://www.labnol.org/internet/tools/using-wikipedia-api-demo-source-code-example/3076/
Tags: api, Archives, code, guest, hacks, javascript, wikipedia, Internet, Tools

Reader Comments
Thats one interesting article!
Can you point me to wikipedia api’s homepage/documentation?
Thanks.
Written by Manjusha on 08.04.08
Is there a maximum number of requests per 24 hours for Wikipedia’s API?
Written by Random Thoughts on 10.01.08
That is great but where is the main api homepage for wikipedia????
thanks
Written by a ahassan on 01.08.09
A few people are looking for the Wikipedia API so i figured i’d pass on what i’ve discovered:
Going to the page mentioned in the code of this article without any search terms gives a nice plain text bit of documentation:
link
For those who want HTML this page then points you on to the mediawiki API page:
link
Mediawiki is the freely distributed open source engine behind Wikipedia.
Written by daveshaw on 02.06.09
LOL! India – porn star!!! haha nice example :P
Written by Larry J. on 02.23.09