baldeweg/api-bundle

Offers tools for API's.

Installs: 606

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Type:symfony-bundle

v55.0.3 2023-09-19 15:35 UTC

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