You are here

public function DiscoveryController::methods in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x modules/jsonrpc_discovery/src/Controller/DiscoveryController.php \Drupal\jsonrpc_discovery\Controller\DiscoveryController::methods()

List the available methods.

Return value

\Drupal\Core\Cache\CacheableJsonResponse The response object.

1 string reference to 'DiscoveryController::methods'
jsonrpc_discovery.routing.yml in modules/jsonrpc_discovery/jsonrpc_discovery.routing.yml
modules/jsonrpc_discovery/jsonrpc_discovery.routing.yml

File

modules/jsonrpc_discovery/src/Controller/DiscoveryController.php, line 58

Class

DiscoveryController
The controller that responds with the discovery information.

Namespace

Drupal\jsonrpc_discovery\Controller

Code

public function methods() {
  $cacheability = new CacheableMetadata();
  $self = Url::fromRoute('jsonrpc.method_collection')
    ->setAbsolute()
    ->toString(TRUE);
  $cacheability
    ->addCacheableDependency($self);
  $methods = [
    'data' => array_values($this
      ->getAvailableMethods($cacheability)),
    'links' => [
      'self' => $self
        ->getGeneratedUrl(),
    ],
  ];
  $serialized = $this->serializer
    ->serialize($methods, 'json', [
    AnnotationNormalizer::DEPTH_KEY => 0,
    NormalizerBase::SERIALIZATION_CONTEXT_CACHEABILITY => $cacheability,
  ]);
  return CacheableJsonResponse::fromJsonString($serialized)
    ->addCacheableDependency($cacheability);
}