PHPackages                             flame/tiny-rest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. flame/tiny-rest

ActiveLibrary[Framework](/categories/framework)

flame/tiny-rest
===============

Smart implementation of REST for Nette

v1.1.1(9y ago)101.1k2[1 PRs](https://github.com/flame-org/TinyREST/pulls)BSD-2-Clause-FreeBSDPHPPHP &gt;=5.3.2

Since Aug 20Pushed 9y ago4 watchersCompare

[ Source](https://github.com/flame-org/TinyREST)[ Packagist](https://packagist.org/packages/flame/tiny-rest)[ Docs](https://github.com/flame-org/TinyREST)[ RSS](/packages/flame-tiny-rest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

Nette REST library
==================

[](#nette-rest-library)

Smart and tiny implementation of REST API for Nette framework

Content
-------

[](#content)

1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Configuration](#configuration)
4. [Authentication](#authentication)
5. [Routing and presenters](#routing-and-presenters)
6. [Examples](#examples)
7. [Patrons](#patrons)

Requirements
------------

[](#requirements)

For full requirements list please see [this file](https://github.com/flame-org/TinyRest/blob/master/composer.json)

- PHP 5.4 or higher
- [Nette Framework](https://nette.org) 2.1 or higher

Installation
------------

[](#installation)

The best way to install flame\\tiny-rest is using [Composer](https://getcomposer.org)

```
$ composer require flame/tiny-rest:@dev
```

and register extension:

```
extensions:
    rest: Flame\Rest\DI\RestExtension
```

Configuration
-------------

[](#configuration)

This package provide next options:

- `authenticators` - list of classes implements `Flame\Rest\Security\IAuthenticator` for authentication requests.
- `cors` - List of settings for cross-domain requests
    - `origin` - list of allowed origins, or `*` for all
    - `headers` - list of allowed headers, or `*` for all
    - `methods` - list of allowed methods, or `*` for all
- `ips` - list of allowed IP address, or nothing for allow all
- `referers` - list of allowed referers, or nothing for allow all

Example configuration:

```
tinyRest:
    cors:
        origin: *
        headers: *
        methods: *
    authenticators:
        - My\Super\Authenticator
```

Authentication
--------------

[](#authentication)

This package provide several authorization method.

1. Authorization by IP address - this authorization is enabled automatically when you set `ips` option in config file.
2. Authorization by HTTP referer - this authorization is enabled automatically when you set `referers` option in config file
3. Authentication by settings for cross-domain requests - this authorization is automatically enabled when you set `cors` option in config file and respects [this](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) rules

Next authorization methods is token-based authorization. For this authorization type you must do some steps:

1. You can create own authenticator implements `Flame\Rest\Security\IAuthenticator` or you can use default authenticator from this package
2. You must create own token provider class implements `Flame\Rest\Security\Tokens\ITokenProvider`. This class with `getToken()` must get token from request (request is provided as argument) and create and return a new instance of `Flame\Rest\Security\Tokens\IToken` (there you must create own implementation or you can use default)
3. You must create own implementation of `Flame\Rest\Security\Tokens\ITokenManager` wḧich provides method for validate token and getting identity for concrete token.

Implementation you can see in [Examples](#examples).

Routing and presenters
----------------------

[](#routing-and-presenters)

### Routing

[](#routing)

This package provides one basic route:

```
$router = new RouteList();
$router[] = new RestRoute('Api:V1');

return $router;
```

This route has one optional argument with module path for searching presenter. In this example expects models with names Api and V1.

Structure of URLs which is created by this router is `//[/][/]`. For our example will be `/api/v1/[/][/]`

All this URLs is mapped to actions in presenter by rule `action()` when `POST` = `create`, `PUT` = `update`, `DELETE` = `delete`, `GET` **without id** = `readAll` and `GET` **with id** = `read`. For example:

- `GET /api/v1/accounts` -&gt; `actionReadAll()`
- `GET /api/v1/accounts/1` -&gt; `actionRead($id)`
- `GET /api/v1/accounts/disabled/1` -&gt; `actionReadDisabled($id)`

### Presenter

[](#presenter)

All API presenters should be extended from `RestPresenter`. When you can send data you must it write into `resource`:

```
public function actionRead($id) {
    $this->resource->id = $id;
    $this->resource->name = 'John';
}
```

or for better works you can use `data` property of `resource`

```
public function actionRead($id) {
    $this->resource->data = [
        'id' => $id,
        'name' => 'John'
    ];
}
```

Sending responses is automatically on end of action method with HTTP code 200. When you can change it, you must call `sendResource($code)` manually.

```
public function actionRead($id) {
    $this->resource->data = [
        'id' => $id,
        'name' => 'John'
    ];
    $this->sendResource(500);
}
```

And for processing and logging errors you can use `sendErrorResponse` method.

You can get data from POST, or query by `input` or `getInput()` member. You can get query values by `getQuery()`, `POST` values by `getData()` or `FILES` by `getFiles()`

```
public function actionReadAll() {
    $limit = $this->getInput()->getQuery('limit');
    $this->resource->data = [
        'id' => $,
        'name' => 'John'
    ];
    $this->sendResource(500);
}
```

Examples
--------

[](#examples)

Router:

```
$router = new RouteList();
$router[] = new RestRoute('Api:V1');

return $router;
```

Presenter AccountsPresenter.php

```
class AccountsPresenter extends RestPresenter
{
    /** User @inject */
    public $user;

    /**
     * @User loggedIn
     */
    public function actionReadAll()
    {
        $this->resource->data = $user->getIdentity();
    }
}
```

Create own Token implementation:

```
class Token implements IToken
{
    private $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function getToken()
    {
        return this->token;
    }
}
```

Create a own TokenGetter:

```
class TokenGetter implements ITokenGetter
{
    public function getToken(Request $request)
    {
        return new Token($request->getHeader('Authorozation'));
    }
}
```

Create own TokenManager

```
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'];
    }
}
```

In this example when I send `GET` request on `/api/v1/accounts` with `Authorization: valid` header and use `BasicAuthenticator` for authenticate by `@User` annotation API returns identity of logged user.

\##Patrons **Big thanks to these guys!**

- Ondra Zaruba (aka [@budry](https://github.com/budry))

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 83% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~245 days

Recently: every ~274 days

Total

6

Last Release

3426d ago

Major Versions

v0.5.0 → v1.0.02015-04-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/25aa07e004e9743a4332fbcfd17628e92f82c6457916442530850183cf7c0bf3?d=identicon)[jsifalda](/maintainers/jsifalda)

---

Top Contributors

[![jsifalda](https://avatars.githubusercontent.com/u/1549390?v=4)](https://github.com/jsifalda "jsifalda (225 commits)")[![Budry](https://avatars.githubusercontent.com/u/990676?v=4)](https://github.com/Budry "Budry (43 commits)")[![matyx](https://avatars.githubusercontent.com/u/7956225?v=4)](https://github.com/matyx "matyx (3 commits)")

---

Tags

frameworkrestSimplerestfulsmarttinyflamejsifalda

### Embed Badge

![Health badge](/badges/flame-tiny-rest/health.svg)

```
[![Health](https://phpackages.com/badges/flame-tiny-rest/health.svg)](https://phpackages.com/packages/flame-tiny-rest)
```

###  Alternatives

[flame/modules

Nette modules on the Steroids

1361.6k3](/packages/flame-modules)[phprest/phprest

PHP Rest Framework.

3049.3k](/packages/phprest-phprest)[flame/framework

Flame is simple and smart FRAMEWORK based on Nette

182.5k1](/packages/flame-framework)[kartenmacherei/rest-framework

Micro framework for creating RESTful webservices

1337.6k](/packages/kartenmacherei-rest-framework)[patricksavalle/slim-rest-api

Production-grade REST-API App-class for PHP SLIM, in production on https://zaplog.pro (https://api.zaplog.pro/v1)

101.4k](/packages/patricksavalle-slim-rest-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
