1

I've been trying to find a solution to versioning in Symfony. What would be the best way to do API versioning in Symfony. In Laravel this is pretty simple, see here

You just separate everything in different folders like V1/V2... and you create routes that points to that folder (namespace). But Symfony works differently, it uses annotation to create routes

Elangovan
  • 3,469
  • 4
  • 31
  • 38
FosAvance
  • 2,363
  • 9
  • 36
  • 52

1 Answers1

7

Symfony also provide easy way to version your code. So if you want to separate your controllers in different folders like v1,v2 etc. then you can when import routes add prefix for each folder.

So in config/routes/annotations.yaml or app/config/routing.yml file you can define:

v1_controllers:
    resource: ../../src/Controller/v1  # add correct path
    type: annotation
    prefix: '/v1'

v2_controllers:
    resource: ../../src/Controller/v2  # add correct path
    type: annotation
    prefix: '/v2'

So after this all routes in v1 folder will have prefix v1.

Please check symfony routing.

ilicmsreten
  • 428
  • 2
  • 5