2017 © Pedro PelĂĄez
 

symfony-bundle rest-problem-bundle

way to respect Problem Details for HTTP APIs RFC (http://tools.ietf.org/html/draft-nottingham-http-problem-03)

image

alterway/rest-problem-bundle

way to respect Problem Details for HTTP APIs RFC (http://tools.ietf.org/html/draft-nottingham-http-problem-03)

  • Monday, December 1, 2014
  • by herveleclerc
  • Repository
  • 13 Watchers
  • 4 Stars
  • 570 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

 RestProblemBundle

Bundle to manage Problems in API with Symfony2., (*1)

Build Status, (*2)

This bundle follows the Problem Details for HTTP APIs recommandation., (*3)

 Installation

Edit your composer.json:, (*4)

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

And run Composer:, (*5)

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

Enable your bundle in your AppKernel.php:, (*6)

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Alterway\Bundle\RestProblemBundle\AwRestProblemBundle(),
    );
}

Usage

use Alterway\Bundle\RestProblemBundle\Response\ProblemResponse;
use Alterway\Bundle\RestProblemBundle\Problem;

public function demoAction(Request $request)
{

    $form = // (...)

    $form->bind($request);
    if (!$form->isValid()) {
        $problem = new Problem\InvalidQueryForm($form);
        return new ProblemResponse($problem, 403);
    }
}

 Usage with annotations

Remember to enable annotations :, (*7)

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:, (*8)

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

This will send an application/api-problem+json header:, (*9)

use Alterway\Bundle\RestProblemBundle\Response\ProblemResponse;
use Alterway\Bundle\RestProblemBundle\Controller\Annotations\Problem;

/**
* @Problem
*/
public function demoAction(Request $request)
{

    $form = // (...)

    $form->bind($request);
    if (!$form->isValid()) {
        return new Problem\InvalidQueryForm($form);
    }
}

Problem's types

You need to create your own problem types. There are by default the following problems:, (*10)

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

Todo

Add controllers and route to provide problemType, (*11)

 Contribute

Install dev dependencies:, (*12)

php composer.phar update --dev

Run Behat:, (*13)

./vendor/bin/behat @AwRestProblemBundle

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

Contributors

  • Lead: Jean-François LĂ©pine (Halleck45)
  • Developer: Antoine LĂ©vĂȘque (gh0stonio)

Sponsors

The Versions