oligus / jad
Json Api to Doctrine ORM
Installs: 1 619
Dependents: 1
Suggesters: 0
Security: 0
Stars: 23
Watchers: 5
Forks: 6
Open Issues: 4
Requires
- php: >=7.2
- ext-json: *
- phan/phan: ^2
- symfony/http-foundation: ^4.1
- symfony/validator: ^4.1
Requires (Dev)
- doctrine/orm: ^2.7
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^8.5
- spatie/phpunit-snapshot-assertions: ^2.2
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ^4.4
This package is auto-updated.
Last update: 2024-11-15 05:36:20 UTC
README
JSON Api ❤️ Doctrine ORM
JAD is a library created for rapid development of JSON API backend REST implementation. You can run JAD as a standalone server with php -S (see demo), or you can use it as a middleware in your framework.
It turns doctrine entities (doctrine/doctrine2) to a JSON API resource, or collection of resources automagically.
Requirements
You need to have Doctrine installed and preferably setup before you can use Jad.
Install
composer require oligus/jad
Quick start
- Annotate your entities that you want to expose to JSON-API:
/** * @ORM\Entity * @ORM\Table(name="albums") * @Jad\Map\Annotations\Header(type="albums") */ class Albums { ...
- Setup JAD using current entity manager.
$jad = new Jad(new Jad\Map\AnnotationMapper($em)); $jad->setPathPrefix('/api/v1/jad'); $jad->jsonApiResult();
- Fetch results
GET /api/v1/jad/albums
Contents
Fetching resources with relationships
Deleting resources / relationships
Support
Lumen
Support for lumen via middleware.
In your Lumen bootstrap file (../lumen/bootstrap/app.php)
// Jad middleware $app->middleware([ 'jad' => Jad\Support\Lumen\JadMiddleWare::class, ]); ... // Register Service Providers $app->register(Jad\Support\Lumen\JadServiceProvider::class);
You can go with the default configuration or copy lumen/vendor/oligus/jad/src/Support/Lumen/jad.php
to /lumen/config
and change it there.
Contributing
When contributing to this repository, please first discuss the change you wish to make via issue before making a pull request.
Authors
- Oli Gustafsson - Initial work - oligus
License
This project is licensed under the MIT License - see the LICENSE file for details