PHPackages                             pz/doctrine-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. [HTTP &amp; Networking](/categories/http)
4. /
5. pz/doctrine-rest

ActiveLibrary[HTTP &amp; Networking](/categories/http)

pz/doctrine-rest
================

Rest API library for Doctrine 2 ORM

0.5.0(1y ago)255.7k↓33.3%6[2 issues](https://github.com/R3VoLuT1OneR/doctrine-rest/issues)[2 PRs](https://github.com/R3VoLuT1OneR/doctrine-rest/pulls)1MITPHPPHP ^8.2CI passing

Since Apr 17Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/R3VoLuT1OneR/doctrine-rest)[ Packagist](https://packagist.org/packages/pz/doctrine-rest)[ RSS](/packages/pz-doctrine-rest/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (10)Versions (31)Used By (1)

doctrine-rest
=============

[](#doctrine-rest)

[![Build Status](https://camo.githubusercontent.com/757ea2d60f0e48167e7f26244c8d1f9d6d397fc5cac17916d2b452ef8afbcb25/68747470733a2f2f7472617669732d63692e6f72672f5233566f4c7554314f6e65522f646f637472696e652d726573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/R3VoLuT1OneR/doctrine-rest)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f5dcbb9dd3deb82fd9546b0b91557624a9aa8af34c60ced251886bfa56dfc758/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5233566f4c7554314f6e65522f646f637472696e652d726573742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/R3VoLuT1OneR/doctrine-rest?branch=master)[![Scrutinizer Code Coverage](https://camo.githubusercontent.com/e47068ea4d441daf222811f6513ad6ed8e5ec1efd82c877a2154cecc52a37459/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5233566f4c7554314f6e65522f646f637472696e652d726573742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/R3VoLuT1OneR/doctrine-rest?branch=master)

Framework agnostic, library provides basic tools for implementation of [JSON API](http://jsonapi.org/format/) over Doctrine library

Using by default [`symfony/http-foundation`](https://symfony.com/doc/current/components/http_foundation.html) for requests/responses and [`league/fractal`](https://fractal.thephpleague.com/) for Rest response build.

Install
-------

[](#install)

Add composer package to your project

```
composer require pz/doctrine-rest

```

Usage
-----

[](#usage)

Package provides different actions for data manipulation and formatting.

Create entity and fractal [trasformer](https://fractal.thephpleague.com/transformers/) for the entity.

```
// Entity class to work with
$entityClass = 'User';
$entityTransformer = new EntityTransformer();

```

If you want to use JSON API please implement `JsonApiResource` on your doctrine entity and add next header to request:

```
Accept: application/vnd.api+json

```

Change entity repository to `RestRepository` or create new one.

```
// Provide configured entity manager
$entityManager = getEntityManager()

// Repository that action will work with
$restRepository = new RestRepository($entityManager, $entityManager->getClassMetadata($entityClass));

```

Prepare `RestRequest` entity or implement `RestRequestContract` on your custom `RestRequest` implementation.

```
// Get http request from framework or init yourself
$httpRequest = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$restRequest = new RestRequest($httpRequest);

```

### Collection (Index) action

[](#collection-index-action)

Route request `GET http://localhost/api/{resourceKey}`

```
$action = new CollectionAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

```

Regular response

```
{
    'data': [
        { ...transformer data },
        { ...transformer data },
        { ...transformer data },
    ],
    'meta': [
        'pagination': { ... paginator data },
    ]
}

```

Json api response

```
{
    'data': [
        {
            'id': {entityId},
            'type': {etntityResourceKey},
            'attributes': { ...transformer data },
            'relationships': { ..transformer includes },
            'links': {
                'self': 'http://localhost/api/resourceKey/{entityId}
            }
        },
        ... Other entities
    ],
    'meta': [
        'pagination': { ... paginator data },
    ]
}

```

### Item (Get) action

[](#item-get-action)

Route request `GET http://localhost/api/{resourceKey}/{id}`.

```
$action = new ItemAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

```

Regular response

```
{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

```

Json api response

```
{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

```

### Create action

[](#create-action)

Route request `POST http://localhost/api/{resourceKey}`.

```
$action = new CreateAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

```

Regular response

```
{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

```

Json api response

```
{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

```

### Update action

[](#update-action)

Route request `PATCH http://localhost/api/{resourceKey}/{id}`.

```
$action = new UpdateAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

```

Regular response

```
{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

```

Json api response

```
{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

```

### Delete action

[](#delete-action)

Route request `DELETE http://localhost/api/{resourceKey}/{id}`.

```
$action = new DeleteAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

```

Response

```
HTTP STATUS 204 NO CONTENT

```

Development
===========

[](#development)

Generate doctrine migration diff
--------------------------------

[](#generate-doctrine-migration-diff)

We using doctrine migrations for unit tests database schema.

```
php ./vendor/bin/doctrine-migrations migrations:diff

```

Run tests
---------

[](#run-tests)

```
docker compose run php phpunit
```

###  Health Score

51

↑

FairBetter than 96% of packages

Maintenance65

Regular maintenance activity

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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 ~98 days

Recently: every ~123 days

Total

27

Last Release

378d ago

PHP version history (6 changes)0.0.1PHP ^7.0

0.0.3PHP ^7.1

0.1.0PHP ^7.1|^8.0

0.2.0PHP ^8.0.2

0.3.0PHP ^8.1

0.5.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d3fa6af699b70f877d632ed3dc64cb86da1d6fed4cb5b42d7c09b234fdc7b16?d=identicon)[R3VoLuT1OneR](/maintainers/R3VoLuT1OneR)

---

Top Contributors

[![R3VoLuT1OneR](https://avatars.githubusercontent.com/u/1111188?v=4)](https://github.com/R3VoLuT1OneR "R3VoLuT1OneR (76 commits)")[![jrean](https://avatars.githubusercontent.com/u/5646128?v=4)](https://github.com/jrean "jrean (5 commits)")

---

Tags

restdoctrine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pz-doctrine-rest/health.svg)

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

###  Alternatives

[api-platform/doctrine-orm

Doctrine ORM bridge

243.1M39](/packages/api-platform-doctrine-orm)[ec-cube/ec-cube

EC-CUBE EC open platform.

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

Concrete core subtree split

19159.3k48](/packages/concrete5-core)[api-platform/http-cache

API Platform HttpCache component

223.2M7](/packages/api-platform-http-cache)[gointegro/hateoas

GOintegro HATEOAS Lib

408.0k1](/packages/gointegro-hateoas)[open-dxp/opendxp

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

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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