Symfony api simplifier

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.0 2021-12-29 00:36 UTC

This package is auto-updated.

Last update: 2024-05-06 03:31:00 UTC


README

Installation

  1. composer req rfrommherz/api
  2. config/bundles.php: Add new bundle to bundles.php
Rf\ApiBundle\JwtBundle::class => ['dev' => true],

Usage

ApiDto

ApiDto's can be used as parameters in your controllers. To enable the support for this, your class must extend ApiDto. Each ApiDto is passed to the symfony validator, which enables the support for validation annotations.

use Rf\ApiBundle\Dto\ApiDto;
use Symfony\Component\Validator\Constraints as Assert;

class Fetch extends ApiDto
{
    /**
     * @Assert\NotBlank
     * @Assert\Url
     * @var string
     */
    private string $repositoryUrl;

Arguments will be automatically resolved and can be passed as controller arguments.

public function index(Fetch $fetch): Response
{
    ...
}
curl --location --request GET 'http://localhost/fetch' \
--header 'Content-Type: application/json' \
--data-raw '{
    "repositoryUrl": "http://...",
}'