Skip to content

Commit

Permalink
Will now create routes and forms when needed
Browse files Browse the repository at this point in the history
Lots of cleanup
  • Loading branch information
davidwdan committed Feb 3, 2015
1 parent affe37b commit 0726626
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 338 deletions.
66 changes: 54 additions & 12 deletions README.md
Expand Up @@ -37,7 +37,7 @@ public function registerBundles()

## 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
This bundle depends on a number of other Symfony bundles, so they need to be configured in order for the generator to work properly

```yaml
framework:
Expand Down Expand Up @@ -77,11 +77,6 @@ sensio_framework_extra:

## 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)

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

Generate the REST controller

Expand All @@ -91,15 +86,62 @@ $ php app/console voryx:generate:rest

This will guide you through the generator which will generate a RESTful controller for an entity.

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

```yaml
api_posts:
type: rest
resource: "@AcmeDemoBundle/Controller/PostController.php"
prefix: /api
## Example

Create a new entity called 'Post':

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

Update the database schema:

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

Generate the API controller:

```bash
$ php app/console voryx: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:

Creating a new post (`POST`)

```bash
$ 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`)

```bash
$ 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`)

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

Get one post (`GET`)

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


Delete (`DELETE`)

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


## Related Entities

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
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Expand Up @@ -6,14 +6,17 @@
"authors": [
{
"name": "Matt Bonneau"
},
{
"name": "David Dan"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"friendsofsymfony/rest-bundle": "1.4.*",
"sensio/generator-bundle": "~2.5",
"friendsofsymfony/rest-bundle": "~1.4",
"jms/serializer-bundle": "0.13.*",
"nelmio/cors-bundle": "1.3.*"
"nelmio/cors-bundle": "~1.3"
},
"autoload": {
"psr-0": {
Expand Down
40 changes: 0 additions & 40 deletions src/Voryx/RESTGeneratorBundle/Command/GenerateDoctrineCommand.php

This file was deleted.

0 comments on commit 0726626

Please sign in to comment.