It should be easy to go from seeing a MediaWiki API example, to seeing its dynamic output, to experimenting based on the example.
== Currently ==
We have three ways to make an API request and see a response
- api.php has examples from PHP code shown as query strings ([[ https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bimageinfo | sample]]). Click one and the browser executes it and shows the response.
- GET requests only, no POSTs
- API wiki pages have similar examples using [[https://www.mediawiki.org/wiki/Template:ApiEx | mw:Template:ApiEx]] ([[ https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii | sample]]). Click one and the browser executes it and shows the response, and you can expand to see API response (currently static)
- GET requests only, no POSTs
- the API response is static text that someone copy-pasted
- [[ https://www.mediawiki.org/wiki/Special:ApiSandbox | Special:ApiSandbox ]] is an interactive sandbox. Choose an action and it has buttons to show documentation and examples (generated from source, like api.php). It can do POSTs.
- Doesn't support some query submodules.
Some ideas:
- Link the sample API requests in the first two to Special:ApISandbox, pre-populating its fields.
- In that mode Special:ApISandbox could look more like the api.php help instead of a confusing form.
- We can transclude the generated API help in wiki pages, e.g. `{{Special:ApiHelp/query+extracts}}`
- e.g. [[ https://www.mediawiki.org/w/index.php?title=Extension%3ATextExtracts&diff=1405623&oldid=1395033 | Extension:TextExtracts]]
- Somehow automate the insertion of static API results into the page.
- We could add JavaScript to the first two to give users a little sandbox window. It would initially show the canned example query and show the result; maybe even let you edit the query as in a JSFiddle and see the new results. Similar to OOjsUI demos and the OOjs UI Living Style Guide
- There are some security implications (e.g. vandal modifies wiki page, gets users to make bad API requests).