Download the PHP package bpa/api-sandbox-bundle without Composer
On this page you can find all versions of the php package bpa/api-sandbox-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bpa/api-sandbox-bundle
More information about bpa/api-sandbox-bundle
Files in bpa/api-sandbox-bundle
Package api-sandbox-bundle
Short Description Symfony Bundle for easy creation of API Sandboxes and integration with NelmioApiDocBundle
License
Informations about the package api-sandbox-bundle
API Sandbox Bundle
This bundle is designed to prevent requests using your real controllers and responding with a fake
response you defined. It integrates nicely with NelmioApiDocBundle
and FOSRestBundle
.
When using NelmioApiDocBundle
this bundle will generate curl
examples for your provided sandbox
requests automatically which will show in the documentation.
Requirements
ApiSandboxBundle requires php >= 5.5 and symfony >= 2.7.
Installation
The easiest way to install this library is through composer.
Just add the following lines to your composer.json file and run composer.phar update
:
Configuration
Load the bundle in your AppKernel.php
:
I would recommend to create a new environment for your sandbox by copying the app.php
front controller
to something like app_sandbox.php
. In your new front controller you have to change the following line
to the new environment:
Create a new config_sandbox.yml
in your app/config
directory with the following contents:
This takes all settings from your prod
environment and enables the sandbox for your new sandbox
environment.
Usage
A basic Controller
When using the FOSRestBundle
and NelmioApiDocBundle
for your API an integration within your
application could look something like this:
Using parameters
It's possible to define multiple responses for a single Controller action and distinguish between
them by using the SandboxRequest\Parameter
Annotation like this:
If you now provide the parameter id = 1
the first response will be returned. With id = 2
the second
one is returned and for all other requests the third response will be returned.
Automatic generation of documentation
With all this set up you will see automatically generated examples API documentation with
the NelmioApiDocBundle
. If you designed your own theme for your documentation you are able
to provide your own ExampleGenerator
which only should extend the provided ExampleGenerator
and override the buildExample
method:
Contributing
Please feel free to contribute to this bundle. Any contribution is highly appreciated and will be reviewed.