stfalcon-studio / api-bundle
Base classes and helper services to build API application via Symfony.
Installs: 20 296
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 4
Forks: 6
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.2
- egulias/email-validator: ^4.0
- fresh/datetime: ^3.0
- ircmaxell/password-compat: ^v1.0.4
- justinrainbow/json-schema: ^5.2.12
- predis/predis: ^2.0
- sentry/sentry-symfony: ^4.13.0
- symfony/config: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/flex: ^2.4
- symfony/framework-bundle: ^7.0
- symfony/http-foundation: ^7.0
- symfony/http-kernel: ^7.0
- symfony/serializer: ^7.0
- symfony/translation: ^7.0
- symfony/validator: ^7.0
Requires (Dev)
- doctrine/common: ^3.4
- doctrine/mongodb-odm: ^2.6
- doctrine/orm: ^2.18
- escapestudios/symfony2-coding-standard: ^3.13
- gesdinet/jwt-refresh-token-bundle: ^v1.1.1
- jetbrains/phpstorm-attributes: ^1.0
- lexik/jwt-authentication-bundle: ^v2.20
- phpstan/phpstan: ^1.10.58
- phpstan/phpstan-deprecation-rules: ^1.1.1
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^11.0
- slam/phpstan-extensions: ^6.0
- symfony/asset: ^7.0
- symfony/console: ^7.0
- symfony/dotenv: ^7.0
- symfony/event-dispatcher: ^7.0
- symfony/filesystem: ^7.0
- symfony/form: ^7.0
- symfony/http-client: ^7.0
- symfony/messenger: ^7.0
- symfony/routing: ^7.0
- symfony/security-bundle: ^7.0
- symfony/security-core: ^7.0
- symfony/security-csrf: ^7.0
- symfony/workflow: ^7.0
- twig/twig: ^v3.8
- dev-main
- 3.5.1
- 3.5.0
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.0
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v0.21.0
- v0.20.3
- v0.20.2
- v0.20.1
- v0.20.0
- v0.19.1
- v0.19.0
- v0.18.2
- v0.18.1
- v0.18.0
- v0.17.0
- v0.16.1
- v0.16.0
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.1
- v0.14.0
- v0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-fix-aggregate-interface
This package is auto-updated.
Last update: 2024-11-24 10:58:07 UTC
README
📦 Base classes and helper services to build API application via Symfony.
Installation
composer req stfalcon-studio/api-bundle
Add next dependencies if you want to use JWT auth
composer req gesdinet/jwt-refresh-token-bundle
composer req lexik/jwt-authentication-bundle
Check the config/bundles.php
file
By default, Symfony Flex adds this bundle to the config/bundles.php
file.
In case when you ignored contrib-recipe
during bundle installation it would not be added. In this case add the bundle manually.
# config/bundles.php return [ // Other bundles... StfalconStudio\ApiBundle\StfalconApiBundle::class => ['all' => true], // Other bundles... ];
Set Up Steps
Add mappings to Doctrine ORM config
doctrine: orm: mappings: StfalconApiBundle: ~
Set up a directory for JSON schemas
The default directory is ./src/Json/Schema/
. Or you can change it via bundle configuration.
stfalcon_api: api_host: '%env(APP_API_HOST)%' json_schema_dir: '%kernel.project_dir%/src/Json/Schema/' jwt: enabled: true # set false to disable JWT auth redis_client_jwt_black_list: "@snc_redis.jwt_black_list"
Usage
Dictionary enums
For simple dictionary enums, you can use the DictionaryEnumInteface
interface on Enums.
It will register for serialization like a dictionary, so the result will be like:
{ "id": 1, "value": "Enum name" }
So, now the dictionary action will look like:
#[Route(path: '/foo/bar', name: 'foo_bar', methods: [Request::METHOD_GET])] public function __invoke(): JsonResponse { // ... return new JsonResponse(data: $this->serializer->serialize(FooBar::cases()), json: true); }
In some cases, you may need to serialise dictionary value not as dictionary, for this just add in context parameter default_normalization
with any value.
$this->serializer->serialize($fooBar, 'json', ['default_normalization' => true]);
Contributing
Read the CONTRIBUTING file.