Download the PHP package paknahad/jsonapi-bundle without Composer
On this page you can find all versions of the php package paknahad/jsonapi-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jsonapi-bundle
JsonApiBundle For Symfony
JsonApiBundle is a Symfony bundle. It is the fastest way to generate API based on JsonApi using woohoolabs/yin Library.
Installing
-
Install symfony
-
Install the maker bundle
-
Install the bundle
For Symfony 4 use:
- Add below line to
config/bundles.php
Usage
-
Use below command to generate entities one by one:
for example, Book and Author entity is as follows:
-
Generate CRUD API:
- You can find the generated "collections" for postman and swagger in the following path and then test the API:
Features
Pagination
Sorting
- Ascending on name field:
http://example.com/books?sort=name
- Decending on name field:
http://example.com/books?sort=-name
- Multiple fields:
http://example.com/books?sort=city,-name
- Field on a relation:
http://example.com/books?sort=author.name
Relationships
multiple relationships
Search
As the JSON API specification does not specify exactly how filtering should work different methods of filtering can be used. Each method is supplied with a Finder service. Each registered Finder will be able to append conditions to the search query. If you register multiple Finders they are all active at the same time. This enables your API to support multiple filtering methods.
Basic Finder.
A basic Finder is included in this library offering simple filtering capabilities:
This request will return all the books that author's name begin with hamid
Below line has additional condition: books which have "php" in their title.
Setting a default filter on the IndexAction
By using you can get access on the query object. use "r" alias for referring to the current entity. in this example the "r" refers to the "ProjectEntity"
Other Finders
Currently, the following Finders are available via other bundles:
-
mnugter/jsonapi-rql-finder-bundle - RQL based Finder
- paknahad-jsonapi-querifier-bundle - Querifier based Finder
Creating a custom Finder
A Finder can be registered via a service tag in the services definition. The tag paknahad.json_api.finder
must be
added to the service for the Finder to be resigered.
Example:
Each Finder must implement the Paknahad\JsonApiBundle\Helper\Filter\FinderInterface
interface. Take a look at
\Paknahad\JsonApiBundle\Helper\Filter\Finder
for an implementation example.
If you need more control over the finders, you can instead use \Paknahad\JsonApiBundle\Helper\Filter\FinderSupportsInterface
interface and implement conditional logic inside supports()
method:
Validation
Error on validating associations
Validate attributes if you have defined validators on entities.
Error handler
All errors such as:
- Internal server error (500)
- Not found (404)
- Access denied (403)
has responses like this:
NOTICE: the "meta" field gets filled just on development environment.
Configuration
You can configure this bundle with following options:
Supported documentation schemas are openapi
and swagger
.
If you want to generate controllers in a different namespace, for example Controller\Api
you can use controllerNamespace configuration option.
To prefix Api routes you can use Symfony routes configuration:
All versions of jsonapi-bundle with dependencies
ext-json Version *
sensio/framework-extra-bundle Version ^5.5|^6.0
symfony/orm-pack Version ^1.0|^2.0
symfony/proxy-manager-bridge Version ^4.4|^5.0|^6.0
symfony/psr-http-message-bridge Version ^2.0
symfony/validator Version ^4.4|^5.0|^6.0
doctrine/inflector Version ^2.0
woohoolabs/yin Version ^4.3
nyholm/psr7 Version ^1.4