I'm trying to work with the mediawiki API for a project on FreeCodeCamp. I've read through these pages on the API docs:
And it's still not clear what the real differences are, and when and why I'd need to use each one. Here's three API calls I've made that each produce slightly different results:
en.wikipedia.org/w/api.php?action=opensearch&search=Albert
In this, I get an array with 4 items, the first being the search term, the second being a list of result page titles, the third being a small snippet of each page, and the fourth being the URL to each page.
en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=Albert&format=json
In this one, there's a generator=search
, which I don't understand. On the API page for generators, it just says: Get the list of pages to work on by executing the specified query module.
, which isn't really very helpful. What does this mean?
en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Albert&format=json
This is the same as the previous one except I'm using list=search
.
So my questions are:
Between the first and second calls, I'm using
action=opensearch
andaction=query
: what are the real differences?What are the differences between
list
andgenerator
?And finally, why is it that when using
generator=search
, thegsrprop=snippet
doesn't display any snippets: API Sandbox for this, and why doesinprop=url
not work when usinglist=search
: API Sandbox for this
As you can see, both are nearly identical, except one uses the generator, and the other the list, but both mention inprop=url, and snippets (srprop & gsrprop).