baldeweg / api-bundle
Offers tools for API's.
Installs: 631
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:symfony-bundle
Requires
- php: >=8.2
- symfony/console: ^6.3
- symfony/dependency-injection: ^6.3
- symfony/framework-bundle: ^6.3
- symfony/http-foundation: ^6.3
- symfony/property-access: ^6.3
- symfony/serializer: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.23
- phpunit/phpunit: ^10.3
- symfony/maker-bundle: ^1.50
- symfony/var-dumper: ^6.3
README
Offers tools for API's.
Getting Started
composer req baldeweg/api-bundle
Activate the bundle in your config/bundles.php
, if not done automatically.
Baldeweg\Bundle\ApiBundle\BaldewegApiBundle::class => ['all' => true],
Usage
use Baldeweg\Bundle\ApiBundle\AbstractApiController; use Baldeweg\Bundle\ApiBundle\Response; $response = new Response(); // Contains the keys of the entity you need $fields = ['id', 'name', 'user' => ['id'], 'createdAtTimestamp', 'commentsCount']; // JSON Response with serialized data $response->single($fields, $genre); // single entity $response->collection($fields, $genres); // array of entities $response->invalid(); // Return message and 400 status code $response->deleted(); // Return message and 200 status code // Parse the data from the request and make them available to the form $this->submitForm($request)
test Trait
To make XHR requests easier, there is an ApiTestTrait
trait available for use.
use \Baldeweg\Bundle\ApiBundle\ApiTestTrait;
Maker
- make:api:controller - Create a Controller
- make:api:test - Create a Test