Enabling And Disabling Endpoints
Disable an Endpoint
WARNING
This section describes how to disable an endpoint as a whole. If you are looking to disable an endpoint based on a condition look the Authorizing Requests
There might be times when an endpoint should not be available to the API consumers. In that case, a Forbidden 403
HTTP response code will be returned as response. For example let's assume that we want to disable the endpoint that creates a Post.
Disabling Creations of new models
Suppose we have a model under the namespace of App\Models\Post
, you can disable the creation of new Posts by adding the Post class to the exclude
index of the desired operation(e.g. create, update, delete, 'index', etc )
//config/autopilot-api.php
<?php
return [
'index' => [
'exclude' => [
],
],
'show' => [
'exclude' => [
],
],
'create' => [
'exclude' => [
App\Models\Post::class
],
],
'update' => [
'exclude' => [
],
],
'delete' => [
'exclude' => [
],
],
'attach' => [
'exclude' => [
],
],
'detach' => [
'exclude' => [
],
],
'sync' => [
'exclude' => [
],
],
'settings' => [
],
];
Disabling Deletes to a Model
The same thing applies to all the CRUD
operations, below we have disabled the Delete Operation
<?php
//config/autopilot-api.php
return [
'index' => [
'exclude' => [
],
],
'show' => [
'exclude' => [
],
],
'create' => [
'exclude' => [
],
],
'update' => [
'exclude' => [
],
],
'delete' => [
'exclude' => [
App\Models\Post::class
],
],
'attach' => [
'exclude' => [
],
],
'detach' => [
'exclude' => [
],
],
'sync' => [
'exclude' => [
],
],
'settings' => [
],
];
Disabling Updates to a Model
<?php
<?php
//config/autopilot-api.php
return [
'index' => [
'exclude' => [
],
],
'show' => [
'exclude' => [
],
],
'create' => [
'exclude' => [
],
],
'update' => [
'exclude' => [
App\Models\Post::class
],
],
'delete' => [
'exclude' => [
],
],
'attach' => [
'exclude' => [
],
],
'detach' => [
'exclude' => [
],
],
'sync' => [
'exclude' => [
],
],
'settings' => [
],
];
Disabling Get All/Single/Attach/Detach/Sync Endpoints(s)
The same applies here, simply enter the class namespace to the index, show, attach, detach, or sync keys
of the configuration array, and the endpoint will be disabled.