PHP code example of nglasl / silverstripe-apiwesome

1. Go to this page and download the library: Download nglasl/silverstripe-apiwesome 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/ */

    

nglasl / silverstripe-apiwesome example snippets


DataObjectOutputConfiguration::customise_data_objects('exclude', array(
	'DataObjectName'
));

DataObjectOutputConfiguration::customise_data_objects('

DataObjectOutputConfiguration::customise_data_objects('disabled');

$service = Singleton('APIwesomeService');

$JSON = $service->retrieve('DataObjectName', 'JSON');
$JSON = $service->retrieve('DataObjectName', 'JSON', 5, array(
	'Attribute',
	'ORDER'
), array(
	'Attribute1' => 'value',
	'Attribute2' => 'value'
));

$objects = DataObjectName::get()->toNestedArray();
$JSON = $service->retrieveJSON($objects);

$XML = $service->retrieve('DataObjectName', 'XML');
$XML = $service->retrieve('DataObjectName', 'XML', 5, array(
	'Attribute',
	'ORDER'
), array(
	'Attribute1' => 'value',
	'Attribute2' => 'value'
));

$objects = DataObjectName::get()->toNestedArray();
$XML = $service->retrieveXML($objects);

return $service->retrieveStaged($this->data()->ID, 'JSON');

$objects = $service->parseJSON($JSON);

$objects = $service->parseXML($XML);

$validation = $service->validateToken($this->getRequest()->getVar('token'));
switch($validation) {
	case APIwesomeService::VALID:

		// The token matches the current security token.

		break;
	case APIwesomeService::INVALID:

		// The token does not match a security token.

		break;
	case APIwesomeService::EXPIRED:

		// The token matches a previous security token.

		break;
}