Skip to content

Kirby 4.5.0

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/.

HTTP Basic Auth

You can enable Basic Authentication for the API via the basicAuth config option:

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

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.

PATCH method overwrite

New in 4.5.0

The PATCH method is not available in some shared hosting environments. Therefore, our API will accept POST requests instead of PATCH requests if the API request sends an x-http-method-override header. All Panel API requests will automatically use POST requests and the additional header by default to ensure the best possible compatibility with environments. You can check in the system view to see if your server supports native PATCH requests and disable method overwrites in your config.

return [
  'api' => [
    'methodOverwrite' => false
  ]
];

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'
          ];
        }
      ]
    ]
  ]
];