Use GET http method for API requests that don't send data #21964
Labels
c: APIs
For bugs and features in the Matomo HTTP and plugin APIs.
c: Platform
For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Enhancement
For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone
AJAX requests that go through AjaxHelper are all handled as
POST
s, even when they have noPOST
data.Summary
AjaxHelper treats all requests as
POST
. Many of these requests do not cause change of server state, so by RFC9110, they could beGET
requests. (This does not include API calls which have auth data in POST parameters. Asking whether auth should be done through HTTP Request headers instead is valid, but way beyond the scope of this feature request.)Taking the Matomo trial with demo data as an example, the dashboard issues 17
POST
requests, of which 7 do not carryPOST
data. (The other 10 only carry default API authentication.)Hosting environments may rate-limit
POST
as a brute-force deterrant, so any measure reducing the number of rapid-successionPOST
requests is useful in those environments.Not having explicit flags for this, the best I could come up with was to test for presence of
POST
data and I'm trialling the code in uschwarz/matomo locally to see if anything falls over.Given how far down the call stack this is, there is a risk of side-effects, for example if API endpoints check for the method and reject
GET
if they expect aPOST
, even if they do not takePOST
data. I do not know enough about Matomo's best practices around this to confidently assess this risk. (Requiring explicit flagging asGET
-safe is unlikely to see adoption in the field.)I'll be happy to update with any plugin issues along those lines we encounter locally.
Your Environment
The text was updated successfully, but these errors were encountered: