1. Go to this page and download the library: Download flame/tiny-rest 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/ */
flame / tiny-rest example snippets
$router = new RouteList();
$router[] = new RestRoute('Api:V1');
return $router;
public function actionRead($id) {
$this->resource->id = $id;
$this->resource->name = 'John';
}
public function actionRead($id) {
$this->resource->data = [
'id' => $id,
'name' => 'John'
];
}
public function actionRead($id) {
$this->resource->data = [
'id' => $id,
'name' => 'John'
];
$this->sendResource(500);
}
public function actionReadAll() {
$limit = $this->getInput()->getQuery('limit');
$this->resource->data = [
'id' => $,
'name' => 'John'
];
$this->sendResource(500);
}
$router = new RouteList();
$router[] = new RestRoute('Api:V1');
return $router;
class AccountsPresenter extends RestPresenter
{
/** User @inject */
public $user;
/**
* @User loggedIn
*/
public function actionReadAll()
{
$this->resource->data = $user->getIdentity();
}
}
class Token implements IToken
{
private $token;
public function __construct($token)
{
$this->token = $token;
}
public function getToken()
{
return this->token;
}
}
class TokenGetter implements ITokenGetter
{
public function getToken(Request $request)
{
return new Token($request->getHeader('Authorozation'));
}
}
class TokenManager implements ITokenManager
{
private $sessionManager;
public function __construct(SessionManager $sessionManager)
{
$this->sessionManager = $sessionManager;
}
public function isTokenValid(IToken $token)
{
$item = $this->sessionManager->getSessionByToken($token->getToken());
return $item['expiration'] < new \DateTime();
}
public function getIdentity(IToken $token)
{
$item = $this->sessionManager->getSessionByToken($token->getToken());
return $item['identity'];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.