Download the PHP package dlinsmeyer/api-response-bundle without Composer
On this page you can find all versions of the php package dlinsmeyer/api-response-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dlinsmeyer/api-response-bundle
More information about dlinsmeyer/api-response-bundle
Files in dlinsmeyer/api-response-bundle
Package api-response-bundle
Short Description A Symfony2 bundle for making maintainable API responses easier to build.
License MIT
Informations about the package api-response-bundle
Symfony2 API Response Bundle
-
Installation
To install the API bundle with Composer just add the following to your
composer.json
file:
Now, Composer will automatically download all required files, and install them
for you. All that is left to do is to update your AppKernel.php
file, and
register the new bundle:
-
Configuration
Via Symfony
No additional configuration is needed. The app should properly detect all configurations in this bundle.
Via Silex
Since bundles are merely packages in Silex, we need to do some manual service configuration. Specifically, in this case, for our serializer.
- Pull in
- Add the following to your Silex bootstrap file:
-
Usage
With the introduction of the SerializationAdapterInterface, there are several more ways callers can utilize the response builder.
JMS Serializer
If no other configuration is made, JMS serializer will be used by default.
JSON Serializer
In order to use json_encode serialization, you need to make a config change
Note: By default, this serializer disregards all context-related data such as version, group, etc. Only the response model will be encoded.
Other than that, follow the code sample in the above for usage.
-
Extension
Overriding MixedTypeHandler
A need may arise for you to extend the class. In such instance, perform the following.
Create Overriding Class
Create a class which extends the MixedTypeHandler. Such as below:
Override service
In your calling library's services configuration file, perform the following:
Creating a custom serializer
By default, this library comes with JMS and json_encode() serialization by default. To add support for other serializers, perform the following:
- Create a class that extends the SerializerAdapterInterface
- Create a service definition for that class.
- In your config, define the following:
All versions of api-response-bundle with dependencies
symfony/framework-bundle Version ~2.1
jms/serializer-bundle Version 0.13.*@dev