"As an API Developer, I want to support different request body content types for my endpoints, so that I can handle requests from legacy clients or clients that use a network standard."
Although for new code in the Core REST API we'll almost always be using JSON, some REST APIs implemented in extensions might need other request body media types. Parsoid/PHP, for example, needs to accept JSON, form-urlencoded, and multipart-form data.
We need a mechanism for an extension to declare that an endpoint accepts non-JSON media types. The default should be JSON only; if media types are declared, they have to be exhaustive (i.e. if a list is provided, and JSON isn't on the list, don't accept JSON).
The router should check the media type of an incoming request against the acceptable media types for the endpoint. It should return a 415 error if the media type isn't supported.
It should parse the request body if the media type is known; otherwise it should pass the body directly to the REST Handler. Known media types should be JSON, form-urlencoded, and multipart-form to start. We might support other media types in the future.
Original description by @Arlolra below.
It seems to assume JSON,
$body = json_decode( $request->getBody()->getContents(), true ) ?? ;
On the JS side, we have,
// application/json // application/x-www-form-urlencoded // multipart/form-data
There are a few mocha tests for this which are failing,
RESTBase currently sends everything to Parsoid in JSON, so it hasn't been an issue. But currently, if I attempt to use VE without a RESTBase in the middle (with a setting like),
$wgVirtualRestConfig['modules']['parsoid'] = array( 'url' => 'http://localhost/rest.php', 'domain' => 'localhost', );
It will render a page just fine but saving is broken since it tries to POST in an unsupported encoding.
Not sure that setup is something we want to support going forward though?