A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

Documenting sample code in Javascript for Action API modules

srishakatux

I am trying to obtain login token from the Action API using Fetch in Javascript and encountering CORS issues. format=jsonp works for all GET requests but not for obtaining tokens cross-site.

As providing sample code in Javascript on API docs came up in the recent survey results and we don’t support cross-site data modifying requests, I’m wondering:
a) What is the best way to demonstrate the use of a data-modifying operation via the Action API in Javascript?
b) What would be some possible options for documenting the use of API modules in Javascript? I am thinking maybe:

  • Node.js (server-side)
  • Fetch API (client-side)
  • mediawiki.api.js (for gadget developers)

If I were to pick 1-2 out of these three options, which ones to pick? Any recommendation would be really helpful!

Tgr

I am trying to obtain login token from the Action API using Fetch in Javascript and encountering CORS issues. format=jsonp works for all GET requests but not for obtaining tokens cross-site.

format=jsonp is disallowed for requests that require authentication, since there’s no reliable way to verify where they came from (unlike the Origin header in CORS requests, referrer is not reliably set by all browsers). CORS errors are typically caused by wiki misconfiguration (there’s a whitelist) or by omitting the cors URL parameter.

a) What is the best way to demonstrate the use of a data-modifying operation via the Action API in Javascript?

Best as in most commonly sought (that would be editing, presumably)? Simplest? (Adding something to a watchlist, maybe?) Most likely to cause problems (ie. most complex)? (Uploads, especially chunked uploads. Although those are rarely done with Javascript, I think.)

b) What would be some possible options for documenting the use of API modules in Javascript? I am thinking maybe:

Typically node developers are more competent and gadget developers have better support channels so I’d go with the Fetch API. Depends on the module, though some of them are not really relevant for some of the scenarios.

Here’s a StackOverflow query for checking MediaWiki API questions with some basic filtering / sorting options: https://data.stackexchange.com/stackoverflow/query/edit/1004740