Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eosnewmedia/json-api-server-bundle

The symfony integration for enm/json-api-server.
https://github.com/eosnewmedia/json-api-server-bundle

abstraction api api-server json json-api php php7 reusable symfony symfony-bundle

Last synced: about 2 months ago
JSON representation

The symfony integration for enm/json-api-server.

Awesome Lists containing this project

README

        

JSON API Server-Bundle
======================
[![Build Status](https://travis-ci.org/eosnewmedia/JSON-API-Server-Bundle.svg?branch=master)](https://travis-ci.org/eosnewmedia/JSON-API-Server-Bundle)

The symfony integration for [`enm/json-api-server`](https://eosnewmedia.github.io/JSON-API-Server/).

## Installation

composer require enm/json-api-server-bundle

*****

## Documentation
You should read the docs of [`enm/json-api-server`](https://eosnewmedia.github.io/JSON-API-Server/) first,
since this bundle only integrate its functionalities into your symfony project.

1. [Configuration](#configuration)
1. [Bundles](#bundles)
1. [Config](#config)
1. [Routing](#routing)
1. [Request Handler](#request-handler)
1. [Error Handling](#error-handling)

*****
*****

## Configuration

### Bundles

```php
['all' => true],
// ...
];

```

*****

### Config
All bundle configurations are optional.

```yaml
# 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

```yaml
# 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`):

```yml
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.