enm / json-api-server-bundle
Symfony integration of enm/json-api-server
Installs: 5 622
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 6
Forks: 4
Open Issues: 5
Type:symfony-bundle
Requires
- php: >=7.2
- enm/json-api-server: ^3.0
- guzzlehttp/psr7: ^1.0
- symfony/framework-bundle: ^4.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-11-30 02:04:59 UTC
README
The symfony integration for enm/json-api-server
.
Installation
composer require enm/json-api-server-bundle
Documentation
You should read the docs of enm/json-api-server
first,
since this bundle only integrate its functionalities into your symfony project.
Configuration
Bundles
<?php // confing/bundles.php return [ // ... Enm\Bundle\JsonApi\Server\EnmJsonApiServerBundle::class => ['all' => true], // ... ];
Config
All bundle configurations are optional.
# config/packages/(dev/|prod/|test/|)enm_json_api.yaml enm_json_api_server: debug: false url_prefix: '' # configure this to use a url prefix for your json api routes: e.g. /api/{type}. only needed if a prefix is defined in your routing route_name_prefix: 'enm.json_api' # Prefix of the route names in symfony (for exception handling). only needed if a nam prefix is defined in your routing
Routing
# app/config/routing.yml | config/routes.yaml json_api: resource: "@EnmJsonApiServerBundle/Resources/config/routing.xml"
If you use the predefined routing (without api prefix configuration), the following routes will be matched:
GET /{type}
GET /{type}/{id}
GET /{type}/{id}/relationships/{relationship}
GET /{type}/{id}/{relationship}
POST /{type}
PATCH /{type}/{id}
DELETE /{type}/{id}
POST /{type}/{id}/relationships/{relationship}
PATCH /{type}/{id}/relationships/{relationship}
DELETE /{type}/{id}/relationships/{relationship}
Request Handler
Each request handler can simply be registered via the service container (tag: json_api_server.request_handler
):
AppBundle\RequestHandler\YourRequestHandler: tags: - { name: json_api_server.request_handler, type: 'myResources' }
The tag attribute type
must contain the json api resource type which will be handled by this request handler.
Error Handling
The bundle will handle all exceptions and convert them to valid json api error responses.