Last active
December 17, 2015 00:49
-
-
Save drahak/5523574 to your computer and use it in GitHub Desktop.
Nette REST API resource presenter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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