Skip to content

Kirby 3.8.4

api

Set options for Kirby's REST API

Disable the API

You can completely disable the API for the frontend.

return [
  'api' => false
];

Please note that the Panel also relies on the API – the Panel won't work if you disable the API.

Change the API slug

You can set a custom slug. The default slug is api.

return [
  'api' => [
    'slug' => 'rest'
  ]
];

All endpoints are now available at https://yourdomain.com/rest/.

Allow insecure requests

By default authentication via basic auth is only permitted when https is enabled. In rare cases (e.g. during local development), it might be necessary to allow basic auth even when https is not enabled.

return [
  'api' => [
    'allowInsecure' => true
  ]
];

Please keep in mind that this option makes your Kirby installation less secure.

Custom API elements

Check out the API extension reference to learn more about adding custom API endpoints, models, collections or more. Instead of using a plugin, you can add them to your config options in the same manner.

/site/config/config.php
return [
  'api' => [
    'routes' => [
      [
        'pattern' => 'my-endpoint',
        'action'  => function () {
          return [
            'hello' => 'world'
          ];
        }
      ]
    ]
  ]
];