PHPackages                             amustaine/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. amustaine/tiny-rest

ActiveLibrary

amustaine/tiny-rest
===================

A light rest api framework, fork of RuSS-B/tiny-rest

1.5.1(today)07↑2900%MITPHPPHP ^8.4

Since Mar 1Pushed todayCompare

[ Source](https://github.com/amustaine/tiny-rest)[ Packagist](https://packagist.org/packages/amustaine/tiny-rest)[ RSS](/packages/amustaine-tiny-rest/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (11)Versions (42)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 amustaine/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

### Attributes

[](#attributes)

#### Property

[](#property)

```
#[Property(name: 'foo', mapped: true, type: 'datetime')]
public $foo;
```

`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 attribute should be used for describing the transfer strategy with the entity. By default the column name equals to the name of the property. The attribute cannot be used without `#[Property]` attribute

```
#[Property]
#[Mapping(column: 'someEntityField', mapped: true)]
public $field;
```

`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)

```
#[Property]
#[Relation(byField: 'slug')]
public $relatedEntity;
```

The `#[Relation]` attribute 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)

```
#[OnObjectValid(callback: [OtherClass::class, '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

55

—

FairBetter than 97% of packages

Maintenance100

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.9% 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 ~77 days

Recently: every ~46 days

Total

36

Last Release

0d ago

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

1.3.0.x-devPHP ^7.2

1.3.11PHP ^8.0

1.3.12PHP ^8.1

1.4.1PHP ^8.3

1.4.6PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3786900?v=4)[alexbuturlakin](/maintainers/alexbuturlakin)[@alexbuturlakin](https://github.com/alexbuturlakin)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M401](/packages/easycorp-easyadmin-bundle)[sylius/sylius

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

8.5k5.9M754](/packages/sylius-sylius)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M512](/packages/pimcore-pimcore)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M353](/packages/api-platform-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k64](/packages/open-dxp-opendxp)

PHPackages © 2026

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