sci3ma/sf4-api-versioning

Example of API versioning on Symfony Framework v4

dev-master 2019-03-15 07:27 UTC

This package is auto-updated.

Last update: 2024-04-15 18:47:58 UTC


README

Example of API versioning on Symfony Framework v4

Used additional bundles

  • friendsofsymfony/rest-bundle
  • jms/serializer-bundle
  • sci3ma/sf4grumphp (optional)

Steps to create project

  1. Create Resource/config/api_routing.yaml for controllers routes
  2. Include Resource/config/api_routing.yaml into config/routes.yaml
    1. Add proper prefix with version parameter
    2. Add available/supported versions in .env file
  3. Create Entity with properties:
    1. id
    2. name
    3. age
    4. color
  4. Create Controller and define RESTful actions

Run project

  1. Run build-in php server bin/console server:start
  2. Go to:
    1. [GET] 127.0.0.1:8000/api/v1.1/godzillas/1 and see response with properties:
      1. id
      2. name
      3. age
    2. [GET] 127.0.0.1:8000/api/v1.2/godzillas/1 and see response with properties:
      1. id
      2. name
      3. age
      4. color
    3. [GET] 127.0.0.1:8000/api/v1.3/godzillas/1 and see response with properties:
      1. id
      2. name
      3. age
      4. full_name - which is virtual property
  3. Similarly as example above:
    1. [GET] http://127.0.0.1:8000/api/v1.1/godzillas
    2. [GET] http://127.0.0.1:8000/api/v1.2/godzillas
    3. [GET] http://127.0.0.1:8000/api/v1.3/godzillas

Conclusion

The main goal of versioning api is changing/updating response structure with keeping the older version in the same time.