Skip to content

Repository files navigation

# RestProblemBundle

Bundle to manage Problems in API with Symfony2.

Build Status

This bundle follows the Problem Details for HTTP APIs recommandation.

## Installation

Edit your composer.json:

"require": {
"alterway/rest-problem-bundle" : "master"
}

And run Composer:

php composer.phar update alterway/rest-problem-bundle

Enable your bundle in your AppKernel.php:

// app/AppKernel.phppublicfunctionregisterBundles()
{
$bundles = array(
// ...newAlterway\Bundle\RestProblemBundle\AwRestProblemBundle(),
);
}

Usage

useAlterway\Bundle\RestProblemBundle\Response\ProblemResponse;
useAlterway\Bundle\RestProblemBundle\Problem;
publicfunctiondemoAction(Request$request)
{
$form = // (...)$form->bind($request);
if (!$form->isValid()) {
$problem = newProblem\InvalidQueryForm($form);
returnnewProblemResponse($problem, 403);
}
}

## Usage with annotations

Remember to enable annotations :

sensio_framework_extra:router: { annotations: true }request: { converters: true }view: { annotations: true }cache: { annotations: true }

And to register the autoloader in your app/autoload.php file:

Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass')); 

This will send an application/api-problem+json header:

useAlterway\Bundle\RestProblemBundle\Response\ProblemResponse;
useAlterway\Bundle\RestProblemBundle\Controller\Annotations\Problem;
/*** @Problem*/publicfunctiondemoAction(Request$request)
{
$form = // (...)$form->bind($request);
if (!$form->isValid()) {
returnnewProblem\InvalidQueryForm($form);
}
}

Problem's types

You need to create your own problem types. There are by default the following problems:

  • Problem\InvalidQuery
  • Problem\InvalidQueryForm
  • ...

Todo

Add controllers and route to provide problemType

## Contribute

Install dev dependencies:

php composer.phar update --dev

Run Behat:

./vendor/bin/behat @AwRestProblemBundle

Copyright

Copyright (c) 2013 La Ruche Qui Dit Oui!. See LICENSE for details.

Contributors

  • Lead: Jean-François Lépine (Halleck45)
  • Developer: Antoine Lévêque (gh0stonio)

Sponsors

About

Allow to manage Rest Problems with Symfony2

Resources

Stars

5 stars

Watchers

12 watching

Forks

Releases

Packages

Contributors

Languages