API Usage

Last updated on
27 March 2025

This documentation needs review. See "Help improve this page" in the sidebar.

The simplest way to install the Decoupled Menus feature is to just enable the module in core. That’s it! Once it is turned on, the endpoint will be active and you will be able to access menu data. Simple, fast, and easy.

The decoupled menus module is now in core.

For versions of Drupal previous to 10.1.0, the Decoupled Menus endpoint is provided by a contributed module that can be required using composer:
composer require 'drupal/decoupled_menus:^1.0@beta'
After enabling the module, the endpoint will be active and you will be able to access menu data. Simple, fast, and easy.

Getting Menu data

Menu data is available at /system/menu/[menu name]/linkset, where "[menu name]" is the machine name of the menu. For instance, to retrieve the main menu:
curl http://localhost:8888/system/menu/main/linkset

If your frontend is on a different domain than your backend, you can enable CORS headers to allow javascript requests to work from the frontend.

To access the menu data in a different language add the language prefix or language domain to the request. To get the menu in Spanish, add the es prefix to the URL.

curl http://localhost:8888/es/system/menu/main/linkset

The endpoint respects user permissions, so you can only access the admin menu data when logged in with an appropriate user account.

curl http://localhost:8888/system/menu/admin/linkset

Sample response format

The format of the response follows the linkset IETF draft to allow some predictability on the structure of the response. This adherence to industry standards is a common pattern in Drupal.
The menu data is returned in a flat array, the information in the drupal-menu-hierarchy makes it possible to render the structured menu.
{
  "linkset": [
    {
      "anchor": "/system/menu/admin/linkset",
      "item": [
        {
          "href": "/admin",
          "title": "Administration",
          "hierarchy": [
            "0"
          ],
          "machine-name": [
            "admin"
          ]
        },
        {
          "href": "/admin/content",
          "title": "Content",
          "hierarchy": [
            "0",
            "0"
          ],
          "machine-name": [
            "admin"
          ]
        },
        {
          "href": "/admin/structure",
          "title": "Structure",
          "hierarchy": [
            "0",
            "1"
          ],
          "machine-name": [
            "admin"
          ]
        },
        {
          "href": "/admin/structure/block",
          "title": "Block layout",
          "hierarchy": [
            "0",
            "1",
            "0"
          ],
          "machine-name": [
            "admin"
          ]
        },
        {
          "href": "/admin/structure/block-content",
          "title": "Block types",
          "hierarchy": [
            "0",
            "1",
            "1"
          ],
          "machine-name": [
            "admin"
          ]
        }
      ]
    }
  ]
}

Help improve this page

Page status: Needs review

You can: