REST's Request handler doesn't resolve $data argument for put and delete methods

Created on 5 August 2021, about 3 years ago
Updated 20 August 2024, about 2 months ago

Problem/Motivation

Unable to pass $data/unserialized parameter containing request body to method 'put' of custom rest resource plugin. This type of request is not considered in \Drupal\rest\RequestHandler::createArgumentResolver when preparing list of available arguments for argument resolver. I suppose it was not considered due to https://groups.drupal.org/node/284948.

Steps to reproduce

  1. Implement a custom rest resource
  2. Implement method 'put' in the custom rest resource with parameter $data or $unserialized
  3. Make a PUT request to the custom rest resource

Proposed resolution

Change condition from

if (in_array($request->getMethod(), ['PATCH', 'POST'], TRUE)) {

to

if (in_array($request->getMethod(), ['PATCH', 'POST', 'PUT'], TRUE)) {

As I see from https://groups.drupal.org/node/284948, PUT was put off because it adds problems for dealing with rest resources for entities. But there are cases when developers create rest resources not dealing with any entity. In this case the developers are fully responsible for logic of such resources including method 'put'. They probably don't face problems described in https://groups.drupal.org/node/284948 . So, I think we should allow such developers to implement proper REST API with support of PUT. Also, PUT is allowed by the rest resource base class. So, I think we should keep support of PUT on the basic level of rest resources since it was already done.

Remaining tasks

No

User interface changes

No

API changes

No

Data model changes

No

Release notes snippet

Fixed argument resolver for methods 'put' and 'delete' of REST resource plugins so, that now it provides request body to parameters with name $data or $unserialized.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
RESTΒ  β†’

Last updated 4 days ago

Created by

πŸ‡·πŸ‡ΊRussia sergei_brill

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024