Create an additional controller with the controllerClassPrefix as prefix (e.g: MyControllerExample where MyController is the defined controllerClassPrefix).
Execute a POST request to the API (e.g: POST yoursite.com/rest/example
Observed behavior
This will produce a method not allowed error because the controller corresponding to the action can not be found.
Expected behavior
When doing a POST request modRestService should find the right controller to process the request.
Workaround
After calling $rest->prepare() (when using the example from the documentation) add the following code:
this does not work in all environments
Bug report
Summary
modRestService is unable to determine the controller when doing a POST request.
When calling
modRestService::prepare
it callsmodRestServiceRequest::setAction
with an empty parameter.modRestServiceRequest::setAction
will then determine's the action by checking therequestParameter
inside$_GET
: https://github.com/modxcms/revolution/blob/932472d65793a305bd8c971f21032f24068258ad/core/model/modx/rest/modrestservice.class.php#L282-L295Therefore when doing a POST request it would fall back to the default action. The action is used to figure out what controller to use when processing the request: https://github.com/modxcms/revolution/blob/932472d65793a305bd8c971f21032f24068258ad/core/model/modx/rest/modrestservice.class.php#L187
Step to reproduce
controllerClassPrefix
as prefix (e.g: MyControllerExample whereMyController
is the definedcontrollerClassPrefix
).POST yoursite.com/rest/example
Observed behavior
This will produce a
method not allowed
error because the controller corresponding to the action can not be found.Expected behavior
When doing a POST request
modRestService
should find the right controller to process the request.Workaround
After calling
$rest->prepare()
(when using the example from the documentation) add the following code: this does not work in all environmentsEnvironment
MODX 2.7.2 and up, NGINX