I
I
Igor2020-04-17 12:36:27
symfony
Igor, 2020-04-17 12:36:27

API versioning in Symfony?

Colleagues, good afternoon!

We are working on a small project.
We write an API.

At this stage, we are thinking about how different versions of the API could be implemented.
We all perfectly understand what versions are for and what it will lead to if this feature is not implemented in the project.
The question is to find the best practice.

We suggest several options.

1. Pass the version number as a parameter when making a request, as vk.com does this.
https://domain.com/users.get?v=0.1
Implement some mechanism inside, we assume that it will be some kind of trash with new functions.

2. Since the project will be completely "dockerized", it would be possible to fork the project and change the configuration.
At the same time, you do not have to produce routes, methods, ...
And it seems to me that this is a parallel with VCS. If we are talking about a fundamental change in the application logic.

What other ways are there?

Symfony 5

FOSRestBundle not offered, does not work in Symfony 5.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2020-04-17
@IgorPI

I propose to work as all the rules guys

  • Create controllers folder /V2/ (well, or/and add V2 to controller name for easy search in IDE)
  • Set the prefix for all these controllers as /v2one line in the routes (well, or if you specify in the annotations -- specify the prefix in them)

Doka: Route Groups and Prefixes¶
And don't mess around with the Query parameter.
Such features are at your fingertips, what parameter did you think of back in the 2000s?!
Well, of course, if you didn’t pile up shit in the controllers, if it’s done cleanly, then the controller is like a consumable, a
controller + a couple of DTOs for the required
UPD version from tommy-vercetti :
You should not use JMS serializer or Symfony Serializer with entity annotations. For responses, you can use regular DTOs or fractal.
It is convenient to write an API for a dock using https://github.com/bukalapak/snowboard

G
grabbee, 2020-04-18
@grabbee

Versioning is considered obsolete by some.
It is recommended to use " deprecated "
https://api-platform.com/docs/core/deprecations/#d...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question