<commit_before>Step 3: Listener support
========================

There are at least 4 listeners. Listeners are a way to hook into the REST handling of
a request and in the preparation of a response to send back. The hooks in view relate
to getting things from the request (parameter fetcher listener), doing some processing
with the payload gotten from a request (body listener), formatting the response either
with a template engine like twig or to json format or xml via the serializer (format
listener), and finally also how to affect the response like in the previous listener
but in things relating to the view (view response listener).

With this in mind we now turn to expound each one of them.

All listeners except the ``mime_type`` one are disabled by default.  You can
enable one or more of these listeners.  For example, below you can see how to
enable all listeners:

```yaml
# app/config/config.yml
fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener: true
    view:
        view_response_listener: 'force'
```

### View Response listener

The view response listener makes it possible to simply return a ``View``
instance from action controllers. The final output will then automatically be
processed via the listener by the ``fos_rest.view_handler`` service.

This requires adding the SensioFrameworkExtraBundle to your vendors:<commit_msg>address comments<commit_after>Step 3: Listener support
========================

[Listeners](http://symfony.com/doc/master/cookbook/service_container/event_listener.html)
are a way to hook into the REST handling of
a request and in the preparation of a response to send back. The hooks in view relate
to getting things from the request (parameter fetcher listener), doing some processing
with the payload gotten from a request (body listener), formatting the response either
with a template engine like twig or to json format or xml via the serializer (format
listener), and finally also how to affect the response like in the previous listener
but in things relating to the view (view response listener).

With this in mind we now turn to explain each one of them.

All listeners except the ``mime_type`` one are disabled by default.  You can
enable one or more of these listeners.  For example, below you can see how to
enable all listeners:

```yaml
# app/config/config.yml
fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener: true
    view:
        view_response_listener: 'force'
```

### View Response listener

The view response listener makes it possible to simply return a ``View``
instance from action controllers. The final output will then automatically be
processed via the listener by the ``fos_rest.view_handler`` service.

This requires adding the SensioFrameworkExtraBundle to your vendors:
{'fraction_non_alphanumeric': 0.06388986939639958, 'fraction_numerical': 0.0010589481115425344, 'mean_word_length': 4.668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '229234', 'n_tokens_mistral': 697, 'n_tokens_neox': 676, 'n_words': 394}