Reading API documentation

Now we're ready to start making API requests! To do that, let's look at Wikipedia's API documentation.

Here's a screenshot of, the homepage for Wikipedia's API (it's also the API used by WikiHow and other MediaWiki projects). Often, the homepage of an API's documentation will provide a deep overview of how the API is structured and the kinds of requests included in it. It's very useful information but not something you need to read through at the moment. The one thing on the homepage I'd like to focus on briefly is the section about the endpoint:

"Endpoint" is a term you'll see in most API documentation which just means the url you'll be using to do the thing being described. This means that all requests using the Wikipedia API will look like[whatever else is going on in our request]. Keep that in mind since all the other pages in this documentation won't refer to the base URL, and will just tell you what to add to it.

Next, we're going to look at the page that describes how to request random articles. I found by googling "wikipedia api random," but you could also use the MediaWiki API search box.

Since an API request is made out of a url and parameters, this page tells us everything we need to know to request random articles from the API. There are 4 optional parameters, rnlimit, rnnamespace, rnredirect, and rnfilterredir. We'll only be using rnnamespace in this tutorial. We will set it to 0, so we only get articles, as opposed to pages like user profiles and discussions about articles.

Looking at the example provided, we can see that the base url is unchanged. The only necessary addition is adding the parameters action=query, list=random, and rnnamespace=0.

results matching ""

    No results matching ""