- 🇮🇳India hardikpandya
I am facing the same issue wherein the `Body` is missing and hence it is not possible to Try Out POST requests from Swagger.
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.
Active
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
I am facing the same issue wherein the `Body` is missing and hence it is not possible to Try Out POST requests from Swagger.