2017 © Pedro Peláez
 

symfony-bundle restgeneratorbundle

REST API Generator for Symfony 2

image

marks12/restgeneratorbundle

REST API Generator for Symfony 2

  • Monday, November 7, 2016
  • by marks12
  • Repository
  • 1 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 74 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Attention

IT IS JUST TEST. DON`T USE THIS BUNDLE. IT IS BAD AND NOT WORKING. Please use marks12/restgeneratorbundle, (*1)

About

A CRUD like REST Generator, (*2)

Features

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

Installation

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

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

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

public function registerBundles()
{
    $bundles = array(
        //...
          new Marks12\RESTGeneratorBundle\Marks12RESTGeneratorBundle(),
          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

Generate the REST controller, (*6)

$ php app/console marks12:generate:rest

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

Example

Create a new entity called 'Post':, (*8)

$ php app/console doctrine:generate:entity --entity=AppBundle:Post --format=annotation --fields="name:string(255) description:string(255)" --no-interaction

Update the database schema:, (*9)

$ php app/console doctrine:schema:update --force

Generate the API controller:, (*10)

$ php app/console marks12:generate:rest --entity="AppBundle:Post"

Using the API

If you selected the default options you'll be able to start using the API like this:, (*11)

Creating a new post (POST), (*12)

$ curl -i -H "Content-Type: application/json" -X POST -d '{"name" : "Test Post", "description" : "This is a test post"}' http://localhost/app_dev.php/api/posts

Updating (PUT), (*13)

$ curl -i -H "Content-Type: application/json" -X PUT -d '{"name" : "Test Post 1", "description" : "This is an updated test post"}' http://localhost/app_dev.php/api/posts/1

Get all posts (GET), (*14)

$ curl http://localhost/app_dev.php/api/posts

Get one post (GET), (*15)

$ curl http://localhost/app_dev.php/api/posts/1

Delete (DELETE), (*16)

$ curl -X DELETE  http://localhost/app_dev.php/api/posts/1

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

#Form/PostType()

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

The Versions

07/11 2016

dev-master

9999999-dev

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

02/11 2016

0.4.6

0.4.6.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

02/11 2016

0.4.5

0.4.5.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

01/11 2016

0.4.4

0.4.4.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

01/11 2016

0.4.3

0.4.3.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

01/11 2016

0.4.2

0.4.2.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

01/11 2016

0.4.1

0.4.1.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

18/04 2016

0.4.0

0.4.0.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

24/08 2015

0.3.0

0.3.0.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

03/02 2015

0.2.0

0.2.0.0

REST API Generator for Symfony 2

  Sources   Download

MIT

The Requires

 

by Matt Bonneau
by David Dan

12/07 2014

0.1.1

0.1.1.0

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