PHPackages                             russbalabanov/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. [API Development](/categories/api)
4. /
5. russbalabanov/tiny-rest

ActiveLibrary[API Development](/categories/api)

russbalabanov/tiny-rest
=======================

Rest

1.3.10(5y ago)08.5k1[9 issues](https://github.com/RuSS-B/tiny-rest/issues)MITPHPPHP ^7.2CI failing

Since Mar 1Pushed 5y ago2 watchersCompare

[ Source](https://github.com/RuSS-B/tiny-rest)[ Packagist](https://packagist.org/packages/russbalabanov/tiny-rest)[ RSS](/packages/russbalabanov-tiny-rest/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (11)Versions (17)Used By (0)

Tiny-rest
=========

[](#tiny-rest)

Heyyy! I just released this library and currently writing some docs for it, so please wait a while.

But if you are eager and cannot wait:

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

[](#installation)

```
composer require russbalabanov/tiny-rest

```

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

[](#configuration)

Please modify your `services.yaml` file to register this two services

```
...

TinyRest\Pagination\PaginationFactory:
TinyRest\RequestHandler:

```

Transfer Objects
----------------

[](#transfer-objects)

Transfer object is a tiny wrapper for HTTP request. The transfer object SHOULD NOT contain entities or convert some user data into complex custom objects. The general idea is having a validatable object which will contain pure user data

### Annotation

[](#annotation)

#### Property

[](#property)

```
@Property(name="foo", mapped=true, type="datetime")

```

`name` - By default the name equals to the name of the property but can be changed for the cases when there is manual mapping needed

`mapped` - whether the value will be set to Transfer object or not. Default: *true*

`type` - There are cases when the value should be casted to a certain type, for example using Transfer Object as filter in a repository. This types are available for type cast: `string`, `integer`, `float`, `array`, `datetime`, `boolean`. Default value is *string*

#### Mapping

[](#mapping)

The annotation should be used for describing the transfer strategy with the entity. By default the column name equals to the name of the property. The annotation cannot be used without `@Property()` annotation

```
@Mapping(column="someEntityField", mapped=true)

```

`column` - By default the name equals to the name of the property but can be changed for the cases when there is manual mapping needed

`mapped` - Can be set as *false* for cases when the property should not transfer it's data to the entity. Default: *true*

#### Relation

[](#relation)

```
@Relation(byField="slug")

```

The `@Relation()` annotation is built for the cases when the plain value in the transfer object should be converted into relation entity.

`byField` - Default: *id*

#### Events

[](#events)

##### OnObjectHydrated

[](#onobjecthydrated)

```
/**
 * @OnObjectHydrated(method="setTimestamp")
 */
class SomeClass implements TransferObjectInterface
{
    private $timestamp;

    public function setTimestamp()
    {
        $this->timestamp = time();
    }
}

```

Triggers after object hydration but before validation

##### OnObjectValid

[](#onobjectvalid)

```
/**
 * @OnObjectHydrated(callback={"OtherClass", "getRandomNumber"})
 */
class SomeClass implements TransferObjectInterface
{
    public $randomNumber;
}

class OtherClass
{
    public static function getRandomNumber(SomeClass $object)
    {
        $object->randomNumber = mt_rand(1, 10);
    }
}

```

Triggers after object validation

Usage
-----

[](#usage)

### Create, Update, List and Pagination

[](#create-update-list-and-pagination)

The idea of all operations was to allow user to care less about the trivial and usual stuff and focus on business logic

#### Create

[](#create)

To create an entity out of request you will need only three agruments. Request object, TransferObject (as a tiny wrapper for the request) and an Entity object.

```
/**
 * @var Product $product
 */
$product = $handler->create($request, new ProductTransferObject(), new Product());

$em->persit($product);
$em->flush();

```

#### Update

[](#update)

The update method is almost the same as create() with one exception. If you are doing a PUT HTTP method all the ORM fields (except @Id) will be cleared

```
$handler->update($request, new ProductTransferObject(), $product);

$em->flush();

```

#### Pagination

[](#pagination)

```
use TinyRest\Pagination\PaginatedCollection

/**
 * @var PaginatedCollection $collection
 */
$collection = $handler->getPaginatedList($request, new UserTransferObject(), $provider);

```

### Providers for collections

[](#providers-for-collections)

##### ORM

[](#orm)

###### DBAL

[](#dbal)

##### NativeQuery

[](#nativequery)

##### Entity

[](#entity)

##### Array

[](#array)

### Handling exceptions and sending API Errors

[](#handling-exceptions-and-sending-api-errors)

When you don't want to bother much with validation errors, you may want to go for this solution.

```
class ExceptionSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::EXCEPTION => 'onKernelException',
        ];
    }

    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $e = $event->getException();

        if ($e instanceof ValidationException) {
            $error = $this->createValidationMessage($e);

            $response = new JsonResponse($error, 400);
            $response->headers->set('Content-Type', 'application/problem+json');
            $event->setResponse($response);

            return $event;
        }

        return $event;
    }

    private function createValidationMessage(ValidationException $exception) : string
    {
        $violation = $exception->getViolationList()->get(0);

        return sprintf('%s: %s', $violation->getPropertyPath(), $violation->getMessage());
    }
}

```

WARNING: This project is currently in aplha stage, which means minimal risk of BC does exist.

#### Do you like the project? Smash the star button, this will motivate me to make it even better!

[](#do-you-like-the-project-smash-the-star-button-this-will-motivate-me-to-make-it-even-better)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~45 days

Total

12

Last Release

2134d ago

PHP version history (2 changes)v1.0PHP ^7.1.3

1.3.0.x-devPHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc71e7a289076db0625de91c8e8dd98e64b60370fc8aecc13639227a7f8119ca?d=identicon)[RussDeveloper](/maintainers/RussDeveloper)

---

Top Contributors

[![RuSS-B](https://avatars.githubusercontent.com/u/3403762?v=4)](https://github.com/RuSS-B "RuSS-B (64 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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