Using the Wikipedia API - Live Demo with Source Code

Published in: Code - Wikipedia

wikipedia api

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:

<iframe marginwidth="0" marginheight="0" src="" frameborder="0" width="400" scrolling="no" height="40"></iframe>

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 = '**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:

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 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

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Code - Wikipedia

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube