Sometimes we need a MediaWiki API module to take structured data containing arbitrarily many primitive fields as input. Some examples:
- T182052: Batch reading list operations: we want to batch things like list creation to improve database performance and reduce bandwidth use and latency. This would involve sending some data structure like [ { "name": "...", "description": "..." }, ... ].
- T56035: API imageinfo should allow fetching multiple thumbnail sizes: batching thumbnail URL fetches would require submitting filename/height/params triplets.
- Multi-Content-Revisions will allow secondary content slots which hold complex data (such as some serialization of a deep associative array). This will probably open the structured data floodgate for extensions, and we'll want the API to support that.
- We are using Wikibase in more and more places; the flexibility of data structure it provides (by limiting operations to semantic triplets) is great for editors but not so great for API clients. Eventually we'll probably want to provide high-level abstractions for reading and writing that data, which again means a need to take structured input. (An old and by now probably superseded discussion about that is T585: Finalize high-level API.)
Given the action API's choice of using the x-www-form-urlencoded input format (ie. key1=value1&key2=value2&...), the current options for doing this are not great:
- Use a bunch of multivalue input fields, one per type. So for creating multiple lists the request would be something like listname=First|Second|Third&Listdescription=Blah|blah|blah. Besides not being easily human-readable, this deals poorly with optional fields (maybe some lists do not have a description), cannot handle non-string datatypes (null and the empty string are not always the same), or data structures deeper than one level, or any other kind of complex/flexible structure. (It's also problematic for fields that can contain pipe characters. The API has a workaround for that but it's not an elegant one.)
- Use some standard way to encode an arbitrary structure as a string (JSON would be the obvious one) and submit that as a single parameter. This hides the real parameters and loses all the support the API has for parameters (documentation, format checking etc.) A couple of API modules seem to do this anyway (e.g. abusefiltercheckmatch, categorytree, wblexemeaddform, wikispeech, something in Linter).
- Allow POST requests with an application/json mimetype, read parameters from the JSON body. Mostly the same problems as above; a little saner interaction with debugging tools, probably a little insaner interaction with the parameter handling of the API framework.
Adding some kind of REST API support to MediaWiki would probably be the ideal solution, but that seems like a fairly large undertaking. My immediate goal with the RfC is to find a pragmatic solution for T182052: Batch reading list operations (which needs to be done short-term) without increasing maintenance burden for the API. Having a shared understanding of how to deal with this problem in the long term would help inform that work.