Build a REST API Fastest and Easiest Way

You need to think about all of platforms like web, mobile or whatever when you have a great idea. All of your projects might be need to access your resources, like products, users or whatever. So you should develop an API to share your resources with your other projects.

Don’t worry… You can do it easily with NedraRestBundle.

Let say we need to share Book entity as a resource.

Let’s do it!

Add the NedraRestBundle to your project with the following command:
composer require nedra/rest-bundle

Register the following bundles to AppKernel.php

$bundles = array(
// ...
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
new Nedra\RestBundle\NedraRestBundle(),
// ...

Let say we have a Book entity like the following;

Class Book {
private $id;
private $name;
private $author;

and finally we need add the following definitions to app/config/config.yml for configure NedraRestBundle

model: AppBundle\Entity\Book

That’s it!

Let’s check the routing configuration with the following command to see what happened

bin/console debug:router

You should see the auto-generated routes like the following, if everything is okay.

app_book_index             GET         ANY      ANY    /books/                            
app_book_create POST ANY ANY /books/new
app_book_update PUT|PATCH ANY ANY /books/{id}
app_book_show GET ANY ANY /books/{id}
app_book_delete DELETE ANY ANY /books/{id}


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.