Drupal 9.1 REST: Post and patch requests are rejected

For a few days now, I've been observing the same problem in various projects: post and patch requests on some Rest endpoints are being rejected with an Error 500.

Error message from Vue js: Error 500
Error 500: Error message from a Vue js web app when trying to access the Drupal REST endpoint with a post request.

The following error message can be found in the Drupal logs:

Symfony\Component\Routing\Exception\MethodNotAllowedException: in Drupal\Core\Routing\MethodFilter->filter()

The problem seems irrational: the REST Resources were all correctly created and enabled via the Rest UI module with POST or PATCH method respectively, json selected as data format and cookie selected as authentication method.

Interesting: The problem only appeared on remote web servers. It did not happen in local development environments. All requests went through without a hitch.

Workaround: Adjust language settings

All affected pages were multilingual and mostly had "German" selected as the default language. Since all requests run on URLs that are not prefixed with a language selection, I suspect this is a problem in the Drupal routing system. If you call a URL without a language prefix - for example example.com/demo instead of example.com/en/demo - then Drupal internally redirects to the URL with the language prefix. Presumably, this will result in a change to the request header.

.

As a workaround, it helps to adjust the language setting in the user profile. There the value for "Administration page language" should be set to "No preference".

Set Admin Page Language to No preference

 

Comments

Subscribe to my Sunday thoughts

Join a growing community of friendly readers. Every Sunday I share my thoughts about rational thinking, productivity and life.