Step 1: Setting up the bundle

Step 1: Setting up the bundle

A) Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

1
$ composer require friendsofsymfony/rest-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

B) Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new FOS\RestBundle\FOSRestBundle(),
        );

        // ...
    }
}

C) Enable a Serializer

This bundle needs a serializer to work correctly. In most cases, you'll need to enable a serializer or install one. This bundle tries the following (in the given order) to determine the serializer to use:

  1. The one you configured using fos_rest.service.serializer (if you did).
  2. The JMS serializer, if the JMSSerializerBundle is available (and registered).
  3. The Symfony Serializer if it's enabled (or any service called serializer).

That was it!

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.