api.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. .. index::
  2. single: API
  3. API
  4. ===
  5. ``SonataUserBundle`` embeds `Controllers` to provide an `API` through `FOSRestBundle`, with its documentation provided by ``NelmioApiDocBundle``.
  6. Setup
  7. -----
  8. If you wish to use it, you must first follow the installation instructions of both bundles:
  9. * `FOSRestBundle <https://github.com/FriendsOfSymfony/FOSRestBundle>`_
  10. * `NelmioApiDocBundle <https://github.com/nelmio/NelmioApiDocBundle>`_
  11. Here's the configuration we used, you may adapt it to your needs:
  12. .. code-block:: yaml
  13. fos_rest:
  14. param_fetcher_listener: true
  15. body_listener: true
  16. format_listener: true
  17. view:
  18. view_response_listener: force
  19. body_converter:
  20. enabled: true
  21. validate: true
  22. sensio_framework_extra:
  23. view: { annotations: false }
  24. router: { annotations: true }
  25. request: { converters: true }
  26. twig:
  27. exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
  28. In order to activate the API's, you'll also need to add this to your routing:
  29. .. code-block:: yaml
  30. NelmioApiDocBundle:
  31. resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
  32. prefix: /api/doc
  33. sonata_api_user:
  34. type: rest
  35. prefix: /api/user
  36. resource: "@SonataUserBundle/Resources/config/routing/api.xml"
  37. Serialization
  38. -------------
  39. We're using ``JMSSerializationBundle's`` serializations groups to customize the inputs & outputs.
  40. The taxonomy is as follows:
  41. * ``sonata_api_read`` is the group used to display entities
  42. * ``sonata_api_write`` is the group used for input entities (when used instead of forms)
  43. If you wish to customize the outputted data, feel free to setup your own serialization options by configuring `JMSSerializer` with those groups.