enm/json-api-server-bundle

Symfony integration of enm/json-api-server

Installs: 4 882

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 7

Forks: 5

Open Issues: 6

Type:symfony-bundle

3.1.3 2020-01-02 20:01 UTC

README

Build Status

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.

  1. Configuration
    1. Bundles
    2. Config
    3. Routing
  2. Request Handler
  3. Error Handling

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.