PHPackages                             sdsdev/rest-bundle-doctrine - 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. sdsdev/rest-bundle-doctrine

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

sdsdev/rest-bundle-doctrine
===========================

Symfony bundle that enables you to easily expose your Doctrine Entities via REST

0.3.7(1y ago)113Apache-2.0PHPPHP ^8.1

Since Jul 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/BwtSDSDevs/rest-bundle-doctrine)[ Packagist](https://packagist.org/packages/sdsdev/rest-bundle-doctrine)[ RSS](/packages/sdsdev-rest-bundle-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (19)Versions (7)Used By (0)

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

[](#rest-bundle-doctrine)

Thanks to **Philip Washington Sorst** for the inital [Project](https://github.com/dontdrinkandroot/rest-bundle.php) to fork from.

Updated Project to work with Doctrine ORM 3 and Symfony 7.1.\*

About
-----

[](#about)

This Symfony Bundle automatically generates Routes for all registered Doctrine ORM Entities.

It generates [get](#get), [search](#search), [update](#update), [insert](#insert) and [delete](#delete) routes.

Install
-------

[](#install)

Install via composer

```
composer require sdsdev/rest-bundle-doctrine

```

Enable the Bundle in the `config/bundles.php` file of your Symfony project:

```
return [
    ...
    SdsDev\RestBundleDoctrine\DdrRestBundle::class => ['all' => true]
];
```

Register the routes in the `config/routes.xml` file of your Symfony project:

```

...

```

### Authentication

[](#authentication)

To enable the default Symfony `#[CurrentUser]` Authentication on all endpoints do the flowing steps:

- Create new folder in `config/` called `doctrineRest`
- Create a new yaml file in `config/doctrineRest` called `doctrine_rest_auth.yaml`
- Add the following below to `config/doctrineRest/doctrine_rest_auth.yaml`

```
auth:
  true
```

This will enable the basic Symfony auth on all endpoints so they can only be accessed if you are logged in.

[Symfony Security Docs](https://symfony.com/doc/current/security.html)

Usage
-----

[](#usage)

After fully installing there should be routes available for all entities that are registered in the Doctrine ORM

Routes will return or take data in JSON format.

If you want to see a list of all routes use:

```
bin/console debug:router

```

The entityName is the name of your entity in lowercase so `UserRole` would be `userrole`

### Search

[](#search)

```
    /api/doctrine/search/{entityName}

```

*Method: **POST***

#### Request Options

[](#request-options)

Body Schema

```
{
    "associations":[
        "...",
        "..."
    ],
    "filter":[
        {
            "type": "equals",
            "field": "id",
            "value": 1
        }
    ],
    "sort":[
        {
            "field": "id",
            "order": "ASC"
        }
    ],
    "page": 2
}
```

#### Associations

[](#associations)

You can freely add associations that will be loaded **with** the requested entity.

Associations need to be given in snake case and as a string.

Associations can be up to 2 paths deep.

Example:

User has a connected Table UserRole and we want to load it.

Our Body would look like this:

```
{
    "associations":[
        "user_role"
    ]
}
```

###### Nested associations

[](#nested-associations)

For **nested associations** you can chain them with `entity.entity`

e.g. if UserRoles had a connected Table permissions and we want to load them too

Our Body would look like this:

```
{
    "associations":[
        "user_role.permissions"
    ]
}
```

#### Filter

[](#filter)

Available Filters

- `equals`
- `not_equals`
- `gt` (greater than)
- `lt` (less than)

To get for e.x. a User with the id 1 our body would look like this

Our Body would look like this:

```
{
    "filter":[
        {
            "type": "equals",
            "field": "id",
            "value": 1
        }
    ],
}
```

If we want to filter for a User with a specific Role we can also do that

```
{
    "filter":[
        {
            "type": "equals",
            "field": "userRole.id",
            "value": 1
        }
    ],
}
```

This will return all users that have the UserRole with id 1.

If we want to load and filter the association simultaneously we can give the filter a `mode` parameter.

As of writing this doc only `"mode": "full"` is supported everything else will not have any impact.

So if we want to get a User that has the UserRole id 1 and the corresponding UserRole our Body looks like this:

```
{
    "associations":[
        "user_role"
    ],
    "filter":[
        {
            "type": "equals",
            "field": "userRole.id",
            "value": 1,
            "mode": "full"
        }
    ],
}
```

If we want to get all UserRoles but still only Users with the UserRole.id 1 we can just remove the `"mode":"full"` parameter.

#### Sorting

[](#sorting)

We can define sortings to our entities by giving the request body a `sort` array.

Sample Body

```
{
    "sort":[
        {
            "field": "id",
            "order": "ASC"
        }
    ]
}
```

Available sort orders

- `ASC`
- `DESC`

#### Pagination

[](#pagination)

Pagination is enabled by default (`page: 1`, `perPage: 50`) To control Pagination you can pass `page` and `perPage` in your request body.

```
{
    "page": 1,
    "perPage": 20
}
```

### Get

[](#get)

```
    /api/doctrine/get/{entityName}/{id}

```

*Method: **GET***

Returns an Entity with the given name and id.

Get can also use Associations see [Associations](#associations) above.

### Insert

[](#insert)

```
    /api/doctrine/insert/{entityName}

```

*Method: **POST***

Body is a JSON representation of the object that you want to create.

If we assume you have a User Entity User has id, name, username, additionalName, a Country (ManyToOne Entity) and we got a country with id 1 in there.

Your Body to insert a new User would look like this

```
{
    "id": 1,
    "name": "Test User",
    "username": "TestAccount",
    "additionalName": null,
    "country": 1
}
```

(If id is autoincrement you have to delete the `"id"` field in the json)

**If a mandatory foreign key is not set the api will return an Error!**

Returns 201 if successful

### Update

[](#update)

```
    /api/doctrine/update/{entityName}/{id}

```

*Method: **PUT/PATCH***

If we assume you have a User Entity User has id, name, username and we want to update the username

Your Body to update would look like this

```
{
    "username": "New User Name"
}
```

Returns 200 if successful

### Delete

[](#delete)

```
    /api/doctrine/delete/{entityName}/{id}

```

*Method: **DELETE***

Deletes an entity with the given id.

Will return an Error if the id does not exist.

Returns 204 if successful

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% 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 ~6 days

Total

6

Last Release

642d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/357dae649464ee535a4a95afb168c9dd01973b159698c976a938526f9c8050cc?d=identicon)[SdsDev](/maintainers/SdsDev)

---

Top Contributors

[![philipsorst](https://avatars.githubusercontent.com/u/2827467?v=4)](https://github.com/philipsorst "philipsorst (236 commits)")[![BwtSDSDevs](https://avatars.githubusercontent.com/u/175391389?v=4)](https://github.com/BwtSDSDevs "BwtSDSDevs (2 commits)")

---

Tags

restdoctrine

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[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)[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)[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)
