Versioning API in Symfony?

Colleagues, good afternoon!

Develop a small project.
Write API.

At this stage, think how it would be possible to implement different API versions.
We all know for what version and what will result if you do not implement this feature in the project.
The question is finding the best practices.

Expect several options.

1. The version number passed as parameter when you run the query, as it makes vk.com
https://domain.com/users.get?v=0.1
Inside to implement a mechanism, we assume that it will be a trash with new features.

2. As the project is completely "dateiserver" it would be possible to forkat the project and change the configuration.
At the same time, do not have to produce the ranting and methods ...
And I think it's paralleled with VCS. If we are talking about a fundamental change in the application logic.

What other ways?

Symfony 5

FOSRestBundle not offer, Symfony in 5 not working.
April 19th 20 at 12:30
2 answers
April 19th 20 at 12:32
Solution
Offer to work as all the rules guys
  • Create a folder controllers /V2/ (or/and add V2 to the name of the controller for easy search in the IDE)
  • Configure the prefix for all of these controllers /v2 one line in the ranting (or if the annotation -- ask them to specify the prefix)

Doc: Route Groups and Prefixes¶

Not mudkats with kveri-parameter
Such opportunities at your fingertips what you are thinking there as in zero?!

Well, it certainly is, if you are in the controllers of shit not piled, if done cleanly -- the controller as raskhodka,
controller + a couple of DTO to the desired version

UPD from @graciela:
It is not necessary to use the JMS serializer or Symfony Serializer with annotations for entities. For responses you can use regular DTO-shki or fractal.

The API Doc is comfortable to write with https://github.com/bukalapak/snowboard
Suppose and what if the project will dramatically change a number of its modules.
Or concept of change.

What then?

This model will no longer meet the requirements, even if we normal guys. - samantha.Hue commented on April 19th 20 at 12:35
@samantha.Hue, I did not understand

what if the project will dramatically change a number of its modules.

Depends on the policy of backwards compatibility.
Compliant code will have to write a certain way, adding a new feature, is necessary to maintain compatibility with old (or not combine) - Cleve commented on April 19th 20 at 12:38
@samantha.Hue,
example

There is a functional products with one picture. product
Now in version 2 you added a new functionality "all images" item

When you added this option, it became clear that the picture from the table of goods dead weight, maybe they're still there in the table of images, where several of them...
Then you rewrite the code so that data from the provider came from a new table, but in an ATT to version 1 returned the first picture...

If you are beginning to overlap/conflict of functionality -- there are different mistke and classes will help you, it is not so difficult and quite comfortable - Cleve commented on April 19th 20 at 12:41
@samantha.Hue from myself I will add that it is not necessary to use the JMS serializer or Symfony Serializer with annotations for entities. For responses you can use regular DTO-shki or fractal.

The API Doc is comfortable to write with https://github.com/bukalapak/snowboard - graciela commented on April 19th 20 at 12:44
@graciela, a Great addition. - samantha.Hue commented on April 19th 20 at 12:47
Subsequent major versey, such as no longer plan to use the User entity, and suppose that it will be instead of User Account

User and Account be vastly different.

As we understand this table in the database.

users
accounts

If you want to exclude the entity in the next release.
Here is a reasonable question.
Why do we need a users table in v2? - samantha.Hue commented on April 19th 20 at 12:50
@samantha.Hue,
Why do we need a users table in v2?

I want to note that "version 2" -- this in the same app, where is v1
In v2 so this table will not be used, and if the replacement for nick in the accounts, for v1 you need to make tranformation to go to the ATT came data from accounts - Cleve commented on April 19th 20 at 12:53
@Cleve, It's understandable.

But what if in version 2 we it is unnecessary, and in 1 version should not break. - samantha.Hue commented on April 19th 20 at 12:56
@samantha.Huethat not necessary? - Cleve commented on April 19th 20 at 12:59
@Cleve, I mean the difference is the database structure. - samantha.Hue commented on April 19th 20 at 13:02
That is the easiest option, versioning
It
bin/console make:controller Api\V1\Product
bin/console make:controller Api\V2\Product
- samantha.Hue commented on April 19th 20 at 13:05
PS C:\Projects\rit> docker-compose-f dc.dev.yml php app exec bin/api debug:router
 -------------------------- -------- -------- ------ -----------------
 Name Method Scheme Host Path
 -------------------------- -------- -------- ------ -----------------
 app_api_v1_product_index ANY ANY ANY /v1/product.get
 app_api_v2_product_index ANY ANY ANY /v2/product.get
 -------------------------- -------- -------- ------ -----------------
- samantha.Hue commented on April 19th 20 at 13:08
5e99986976cd7549010920.png - samantha.Hue commented on April 19th 20 at 13:11
@samantha.Hue, Yes, it is...
data controllers will arrive via an ATT-shki and transformers, and the logic of their creation and the data source is already set as it should - Cleve commented on April 19th 20 at 13:14
@samantha.Hue, I would only be in the name added to V2:
ProductControllerV2.php - Cleve commented on April 19th 20 at 13:17
April 19th 20 at 12:34
Versioning someone is considered an outdated practice.
It is recommended to use "obsolete"(deprecated)
https://api-platform.com/docs/core/deprecations/#d...

Find more questions by tags APISymfony