# api

Set options for Kirby's REST API

****

****

## Disable the API

You can completely disable the API for the frontend.

```php
return [
  'api' => false
];
```

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

## Change the API slug

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

```php
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:

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

## Cross-Origin Resource Sharing

For browser-based requests from another origin, configure Cross-Origin Resource Sharing via the <a href="https://getkirby.com/docs/reference/system/options/cors">`cors` option</a>.

## Allow insecure requests

By default authentication via <a href="https://getkirby.com/docs/guide/api/authentication#http-basic-auth">basic auth</a> 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.

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

<warning>
Please keep in mind that this option makes your Kirby installation less secure.
</warning>

## PATCH method override

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 overrides in your config.

```php
return [
  'api' => [
    'methodOverride' => false
  ]
];
```

## Custom API elements

Check out the <a href="https://getkirby.com/docs/reference/plugins/extensions/api">API extension reference</a> 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.

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