Download the PHP package sdsdev/rest-bundle-doctrine without Composer
On this page you can find all versions of the php package sdsdev/rest-bundle-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package rest-bundle-doctrine
rest-bundle-doctrine
Thanks to Philip Washington Sorst for the inital Project to fork from.
Updated Project to work with Doctrine ORM 3 and Symfony 7.1.*
About
This Symfony Bundle automatically generates Routes for all registered Doctrine ORM Entities.
It generates delete routes.
Install
Install via composer
Enable the Bundle in the config/bundles.php
file of your Symfony project:
Register the routes in the config/routes.xml
file of your Symfony project:
Authentication
To enable the default Symfony #[CurrentUser]
Authentication on all endpoints do the flowing steps:
- Create new folder in
config/
calleddoctrineRest
- Create a new yaml file in
config/doctrineRest
calleddoctrine_rest_auth.yaml
- Add the following below to
config/doctrineRest/doctrine_rest_auth.yaml
This will enable the basic Symfony auth on all endpoints so they can only be accessed if you are logged in.
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:
The entityName is the name of your entity in lowercase so UserRole
would be userrole
Search
Method: POST
Request Options
Body Schema
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:
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:
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:
If we want to filter for a User with a specific Role we can also do that
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:
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
We can define sortings to our entities by giving the request body a sort
array.
Sample Body
Available sort orders
ASC
DESC
Pagination
Pagination is enabled by default (page: 1
, perPage: 50
)
To control Pagination you can pass page
and perPage
in your request body.
Get
Method: GET
Returns an Entity with the given name and id.
Get can also use Associations see Associations above.
Insert
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
(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
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
Returns 200 if successful
Delete
Method: DELETE
Deletes an entity with the given id.
Will return an Error if the id does not exist.
Returns 204 if successful
All versions of rest-bundle-doctrine with dependencies
jms/metadata Version ^2.6
doctrine/orm Version ^3.1
symfony/expression-language Version 7.1.*
symfony/finder Version 7.1.*
symfony/framework-bundle Version 7.1.*
symfony/property-access Version 7.1.*
symfony/security-bundle Version 7.1.*
symfony/serializer Version 7.1.*
symfony/validator Version 7.1.*
symfony/yaml Version 7.1.*