PHP code example of emteknetnz / silverstripe-rest-api
1. Go to this page and download the library: Download emteknetnz/silverstripe-rest-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
emteknetnz / silverstripe-rest-api example snippets
use SilverStripe\Core\Environment;
use SilverStripe\Security\SecurityToken;
// ...
if (Environment::getEnv('DISABLE_API_CSRF_TOKEN_CHECK')) {
SecurityToken::disable();
}
use emteknetnz\RestApi\Controllers\RestApiEndpoint;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataObject;
class MySiteTreeEndpoint extends RestApiEndpoint
{
private static array $api_config = [
RestApiEndpoint::PATH => 'api/pages',
RestApiEndpoint::DATA_CLASS => SiteTree::class,
RestApiEndpoint::ACCESS => RestApiEndpoint::LOGGED_IN,
RestApiEndpoint::ALLOWED_OPERATIONS => RestApiEndpoint::VIEW_CREATE_EDIT_DELETE_ACTION,
RestApiEndpoint::FIELDS => [
'title' => 'Title',
],
];
protected function onEditBeforeWrite(SiteTree $page)
{
// You wouldn't normally do this, this is only for demo purposes
$page->Content .= '<p>This was updated using the API</p>';
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.