rezzza / symfony-rest-api-json
Stuff to let symfony app support JSON rest api operation
2.1.2
2017-11-29 17:23 UTC
Requires
- jakeasmith/http_build_url: ^1.0
- justinrainbow/json-schema: >=3.0 <6.0
- symfony/debug: ^2.8|^3.0|^4.0
- symfony/http-foundation: ^2.8|^3.0|^4.0
- symfony/http-kernel: ^2.8|^3.0|^4.0
Requires (Dev)
- atoum/atoum: ^3.1
- fzaninotto/faker: ^1.5
- guzzlehttp/psr7: ^1.3
- league/tactician-bundle: ^0.4.1
- php-http/curl-client: ^1.5
- rezzza/rest-api-behat-extension: ^6.0
- symfony/framework-bundle: ^3.0
- symfony/serializer: ^3.0
- symfony/validator: ^3.0
Suggests
- league/tactician-bundle: Support for ValidatorMiddleware of TacticianBundle
- symfony/serializer: Support for ValidatorMiddleware of TacticianBundle
This package is not auto-updated.
Last update: 2024-12-21 20:46:43 UTC
README
Symfony stuff to help building a JSON REST api :
- Support JSON payload
- Support LINK headers
- Handle exception as JSON response
- Possibility to validate json payload through json schema
- Possibility to map custom exception to http code
Here is a simple setup to start :
<?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="json_body_listener.ui" class="Rezzza\SymfonyRestApiJson\JsonBodyListener"> <argument type="service"> <service class="Rezzza\SymfonyRestApiJson\PayloadValidator"> <argument type="service"> <service class="Rezzza\SymfonyRestApiJson\JsonSchemaTools" /> </argument> </service> </argument> <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="24" /> </service> <service id="link_request_listener.ui" class="Rezzza\SymfonyRestApiJson\LinkRequestListener"> <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="10" /> </service> <service id="json_exception_handler.ui" class="Rezzza\SymfonyRestApiJson\JsonExceptionHandler"> <argument type="service"> <service class="Rezzza\SymfonyRestApiJson\ExceptionHttpCodeMap"> <argument>%exception_http_code_map%</argument> </service> </argument> <tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="32" /> </service> <service id="json_exception_controller.ui" class="Rezzza\SymfonyRestApiJson\JsonExceptionController"> <argument>%kernel.debug%</argument> <argument>%show_exception_token%</argument> </service> <service id="ui.event_listener.exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener"> <tag name="kernel.event_subscriber" /> <tag name="monolog.logger" channel="request" /> <argument>json_exception_controller.ui:showException</argument> <argument type="service" id="logger" on-invalid="null" /> </service> </services> </container>