2017 © Pedro Peláez
 

symfony-bundle restgeneratorbundle

REST API Generator for Symfony 2

image

testabit/restgeneratorbundle

REST API Generator for Symfony 2

  • Thursday, November 12, 2015
  • by testabit
  • Repository
  • 4 Watchers
  • 0 Stars
  • 150 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 74 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Voryx REST Generator Bundle

SensioLabsInsight, (*1)

About

A CRUD like REST Generator, (*2)

Features

  • Generators RESTful action from entity
  • Simplifies setting up a RESTful Controller

Installation

Require the "voryx/restgeneratorbundle" package in your composer.json and update your dependencies., (*3)

$ php composer.phar require voryx/restgeneratorbundle dev-master

Add the VoryxRestGeneratorBundle to your application's kernel along with other dependencies:, (*4)

public function registerBundles()
{
    $bundles = array(
        //...
          new Voryx\RESTGeneratorBundle\VoryxRESTGeneratorBundle(),
          new FOS\RestBundle\FOSRestBundle(),
          new JMS\SerializerBundle\JMSSerializerBundle($this),
          new Nelmio\CorsBundle\NelmioCorsBundle(),
        //...
    );
    //...
}

Configuration

This bundle depends on a number of other symfony bundles, so they need to be configured in order for the generator to work properly, (*5)

framework:
    csrf_protection: false #only use for public API

fos_rest:
    routing_loader:
        default_format: json
    param_fetcher_listener: true
    body_listener: true
    #disable_csrf_role: ROLE_USER
    body_converter:
        enabled: true
    view:
        view_response_listener: force

nelmio_cors:
    defaults:
        allow_credentials: false
        allow_origin: []
        allow_headers: []
        allow_methods: []
        expose_headers: []
        max_age: 0
    paths:
        '^/api/':
            allow_origin: ['*']
            allow_headers: ['*']
            allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
            max_age: 3600

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

Generating the Controller

Right now, the generator uses forms created by the doctrine generator. You must create these to use the generated controller. (If you don't create them prior to running the voryx:generate:rest command, you will get an error, but it will still work if you just create them afterwards), (*6)

$ php app/console doctrine:generate:form AcmeDemoBundle:Post

Generate the REST controller, (*7)

$ php app/console voryx:generate:rest

This will guide you through the generator which will generate a RESTful controller for an entity., (*8)

You will still need to Add a route for each generated entity: (Hopefully this will be added to the generator soon), (*9)

api_posts:
    type:     rest
    resource: "@AcmeDemoBundle/Controller/PostController.php"
    prefix: /api

If you want the form to be able to convert related entities into the correct entity id on POST, PUT or PATCH, use the voryx_entity form type, (*10)

#Form/PostType()

    ->add(
        'user', 'voryx_entity', array(
            'class' => 'Acme\Bundle\Entity\User'
        )
    )

The Versions

12/11 2015

dev-master

9999999-dev

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau

24/04 2015

dev-put

dev-put

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau

13/04 2015

dev-refactor

dev-refactor

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau

09/04 2015

dev-templates

dev-templates

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau

09/07 2014

0.1.0

0.1.0.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau