You are here

public function DiscoveryController::method 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::method()

Information about the method.

Return value

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

1 string reference to 'DiscoveryController::method'
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 81

Class

DiscoveryController
The controller that responds with the discovery information.

Namespace

Drupal\jsonrpc_discovery\Controller

Code

public function method($method_id) {
  $cacheability = new CacheableMetadata();
  $cacheability
    ->addCacheContexts([
    'url.path',
  ]);
  $methods = $this
    ->getAvailableMethods($cacheability);
  if (!isset($methods[$method_id])) {
    throw new CacheableNotFoundHttpException($cacheability, "The {$method_id} method is not available.");
  }
  $serialized = $this->serializer
    ->serialize($methods[$method_id], 'json', [
    NormalizerBase::SERIALIZATION_CONTEXT_CACHEABILITY => $cacheability,
  ]);
  return CacheableJsonResponse::fromJsonString($serialized)
    ->addCacheableDependency($cacheability);
}