Body section in Custom Rest Post Resource is not shown

Created on 24 March 2020, over 4 years ago
Updated 10 May 2024, about 2 months ago

Hi ,

Thank you for your good module.
I've create a custom resource

with drupal generate:plugin:rest:resource

and the result is

<?php

namespace Drupal\baxter_rest\Plugin\rest\resource;

use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
 * Provides a resource to get view modes by entity and bundle.
 *
 * @RestResource(
 *   id = "post_patient_rest_resource",
 *   label = @Translation("Post patient rest resource"),
 *   uri_paths = {
 *     "create" = "/api/v1/create-patient"
 *   }
 * )
 */
class PostPatientRestResource extends ResourceBase {

  /**
   * A current user instance.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $instance->logger = $container->get('logger.factory')->get('baxter_rest');
    $instance->currentUser = $container->get('current_user');
    return $instance;
  }

    /**
     * Responds to POST requests.
     *
     * @param string $payload
     *
     * @return \Drupal\rest\ModifiedResourceResponse
     *   The HTTP response object.
     *
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
     *   Throws exception expected.
     */
    public function post($payload) {

        // You must to implement the logic of your REST Resource here.
        // Use current user after pass authentication to validate access.
        if (!$this->currentUser->hasPermission('access content')) {
            throw new AccessDeniedHttpException();
        }

        return new ModifiedResourceResponse($payload, 200);
    }

}

Then I enabled it on Rest_ui,

it's available on the list of Swagger, but the body section is empty.

View post on imgur.com

🐛 Bug report
Status

Active

Component

Code

Created by

🇩🇪Germany yuseferi

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

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.69.0 2024