JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol.

This module implements a framework for creating non-RESTful services. It is intended to be the platform on which a decoupled Drupal administration and introspection interface can be built.

While JSON API module handles entity data and REST can be used to create custom REST resources, some Drupal actions can't be neatly handled with REST principles. Clearing cache is a perfect example.

JSON-RPC exposes Drupal internal data like permissions or installed modules. Additionally, JSON-RPC can be used to execute actions remotely against your Drupal application, like clearing caches or putting the site in maintenance mode.

Not all features are implemented. If you would like to help, you can find or add to the list of missing APIs.


Learn more about the motivation and the internals of this module in this article.

Discovery

The available RPC services along with documentation and usage details can be discovered by sending an HTTP GET request to /jsonrpc/methods. To make these available you will need to enable the jsonrpc_discovery sub-module.

Usage

To execute an RPC method, send an HTTP POST request to /jsonrpc. The body of your request must adhere the JSON-RPC specification.

You can also execute an RPC method sending a GET request with a ?query= parameter. Remember to URL-encode the JSON string. Many CDNs only allow caching on GET requests so this is the recommended approach in most situations.

Examples

You can use this Postman Collection with examples and tests. These RPC examples are provided by the jsonrpc_core sub-module. Enable it to see the examples in action.

Example request/response:

Request
POST
{
  "jsonrpc": "2.0",
  "method": "plugins.list",
  "params": {
    "service": "plugin.manager.link_relation_type",
    "page": {
      "limit": 3,
      "offset": 1
    }
  },
  "id": "relation-types"
}

The same request using the GET method (after URL encode) would be:

https://example.org/jsonrpc?query=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22plugins.list%22%2C%22params%22%3A%7B%22service%22%3A%22plugin.manager.link_relation_type%22%2C%22page%22%3A%7B%22limit%22%3A3%2C%22offset%22%3A1%7D%7D%2C%22id%22%3A%22relation-types%22%7D

Response

That will return a list of the relation type plugins available on the site.

{
  "jsonrpc": "2.0",
  "id": "relation-types",
  "result": {
    "add-page": {
      "class": "Drupal\\Core\\Http\\LinkRelationType",
      "uri": "https://drupal.org/link-relations/add-page",
      "description": "A page where a resource of this type and related types can be created.",
      "provider": "core",
      "id": "add-page"
    },
    "delete-form": {
      "class": "Drupal\\Core\\Http\\LinkRelationType",
      "uri": "https://drupal.org/link-relations/delete-form",
      "description": "A form where a resource of this type can be deleted.",
      "provider": "core",
      "id": "delete-form"
    },
    "revision": {
      "class": "Drupal\\Core\\Http\\LinkRelationType",
      "uri": "https://drupal.org/link-relations/revision",
      "description": "A particular version of this resource.",
      "provider": "core",
      "id": "revision"
    }
  }
}

Contenta CMS

This module is part of the Contenta CMS decoupled distribution and integrates with Contenta JS. Learn more about these projects:

Supporting organizations: 
Development and maintenance
Development and maintenance

Project information

Releases