This package can help you build JSON-API Web Service is a few minutes with Flow Framework.
This package is under development and not feature complete
This package is Composer ready, PSR-2 and PSR-4 compliant.
Compatible with Flow 2.3.x (we plan to make it compatible with Flow 3.x as soon as our current customer projet upgrade to Flow 3.x).
This package integrate neomerx/json-api in Flow by providing a API to build JSON-API Web Service by convention. We try to keep this package simple (KISS) and SOLID as much as we can. We focus on read only API currently.
Currently the routing is really basic, check Routes.yaml. The stable version will contain a custom RoutePartHandler for more flexibility.
You can define a Schema Class to convert your object to a JSON API schema. You can start configuring your service,
open your Settings.yaml
and start some definition:
JsonApi:
endpoints:
'default':
baseUrl: 'api/v1/'
version: '0.9.0'
resources:
'movies':
repository: 'Your\Package\Domain\Repository\MovieRepository'
schemas:
'Your\Package\Domain\Model\Movie': 'Your\Package\Schema\MovieSchema'
'Your\Package\Domain\Model\GenericPerson': 'Your\Package\Schema\GenericPersonSchema'
'Your\Package\Domain\Model\Category': 'Your\Package\Schema\CategorySchema'
- Name your preset (default), currently we support only one preset
baseUrl
: The relative base URL of the current preset, must match your Routingversion
: Version of the API, currently not usedresources
: List of Resource to expose in the APIrepository
: Provide a Repository, must implement theJsonApiRepositoryInterface
interface, you can use theJsonApiRepositoryTrait
to remove part of the painschemas
: Mapping between your models and a schema class, check the Schema documentation for more informations
With the given configuration you can open your browser to: http://www.domain.com/api/v1/movies to show the list of resource and to http://www.domain.com/movies/d2dc1c34-549f-39a9-c5fc-d716061b0782 to have a single resource.
The Schema class allow you to control the structure of the JSON, create Links, include some resources, ...
Easy ? No ?
You can use this schema build to expose Doctrine entities. The DynamicEntitySchema
use the schema
definitions stored in your JsonApiSchema.yaml
. You can split your definitions in multiple file,
like JsonApiSchema.Movie.yaml
. A basic definition look like this:
'Your\Package\Domain\Model\Movie':
resourceType: 'movies'
selfSubUrl: '/movies/'
attributes:
short_hash:
property: shortHash
collection_title:
property: title.collectionTitle
local_title:
property: title.localTitle
original_title:
property: title.originalTitle
teaser:
property: teaser
description:
property: description
relationships:
actors:
data:
property: directors
showRelated: TRUE
directors:
data:
property: directors
showRelated: TRUE
includePaths:
directors: TRUE
actors: TRUE
When your Schema definition in YAML is done done, you can configure your endpoint like this:
JsonApi:
endpoints:
'default':
baseUrl: 'api/v1/'
version: '0.9.0'
resources:
'movies':
repository: 'Your\Package\Domain\Repository\MovieRepository'
schemas:
'Your\Package\Domain\Model\Movie': 'Ttree\JsonApi\Schema\DynamicEntitySchema'
'Your\Package\Domain\Model\GenericPerson': 'Your\Package\Schema\GenericPersonSchema'
'Your\Package\Domain\Model\Category': 'Your\Package\Schema\CategorySchema'
You can use this schema build to expose TYPO3CR entities.
[currently not supported, check feature list]
By default sorting is disabled, you need to configure explicitly the attributes where sorting is allowed. This
configuration can be done for each endpoints. In the exemple bellow only the attribute title
is allowed in the
sort
request parameter.
JsonApi:
endpoints:
'default':
baseUrl: 'api/v1/'
version: '0.9.0'
resources:
'movies':
repository: 'Your\Package\Domain\Repository\MovieRepository'
sortableAttributes:
'title': 'title'
schemas:
'Your\Package\Domain\Model\Movie': 'Ttree\JsonApi\Schema\DynamicEntitySchema'
'Your\Package\Domain\Model\GenericPerson': 'Your\Package\Schema\GenericPersonSchema'
'Your\Package\Domain\Model\Category': 'Your\Package\Schema\CategorySchema'
- Fetching Resources
- Fetching Resource
- Fetching Relationships
- Compound Documents
- Sparse Fieldsets
- Schema generation based on YAML definition for Doctrine entites
- Property post processors based on EEL during Schema generation
- Sorting
- Pagination (page[number] / page[size] and page[offset] / page[limit])
- Configure defautl pagination strategy, currently hardcode to page[number] & page[size]
- Error Handling
- Schema generation based on YAML definition for TYPO3CR nodes
- Filtering
- Caching
Development sponsored by ttree ltd - neos solution provider.
We try our best to craft this package with a lots of love, we are open to sponsoring, support request, ... just contact us.
The MIT License (MIT). Please see LICENSE for more information.