Skip to content

Instantly share code, notes, and snippets.

@drahak
Last active December 17, 2015 00:49
Show Gist options
  • Save drahak/5523574 to your computer and use it in GitHub Desktop.
Save drahak/5523574 to your computer and use it in GitHub Desktop.
Nette REST API resource presenter
namespace ResourcesModule;
use Drahak\Api\IResource;
/**
* SamplePresenter resource
* @package ResourcesModule
* @author Drahomír Hanák
*/
class SamplePresenter extends BasePresenter
{
protected $typeMap = array(
'json' => IResource::JSON,
'xml' => IResource::XML
);
/**
* @GET sample/?type=<type>
*/
public function actionContent($type = 'json')
{
$this->resource->title = 'REST API';
$this->resource->subtitle = '';
$this->sendResource($this->typeMap[$type]);
}
/**
* @GET sample/detail
*/
public function actionDetail()
{
$this->resource->message = 'Hello world';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment