-1

Hi I would like to version my API. So I would like t prefix my roote with a version. like that?

# config/routes/annotations.yaml

controllers:
    resource: ../../src/Controller/
    type: annotation
    prefix:
        name: '{version}'

It works bit I would like to add a requirement to check the version.

Like:

requirements:
     version:  v1|v2

I don't find any documentation talking about that. Is there a good way to do it?

Kevin
  • 4,823
  • 6
  • 36
  • 70

1 Answers1

2

In the FOSRestBundle there is a complete chapter about versioning.

https://symfony.com/doc/master/bundles/FOSRestBundle/versioning.html

The FOSBundle has an option for versioning.

#app/config/config.yml
fos_rest:
    versioning:
        enabled: true
        resolvers:
            query: true # Query parameter: /users?version=v1
            custom_header: true # X-Accept-Version header
            media_type: # Accept header
                enabled: true
                regex: '/(v|version)=(?P<version>[0-9\.]+)/'
René Höhle
  • 26,716
  • 22
  • 73
  • 82