A
A
Alexey Konovalov2018-03-06 18:44:19
API
Alexey Konovalov, 2018-03-06 18:44:19

How to separate API versions on the server?

Hello! I am writing an API in php. Quite voluminous, but I don’t quite understand how to do it, several versions of it ...
For example, a request can come with the v1.0.0 parameter , but suddenly I needed to create version v1.0.1, in order, for example, to add one more parameter when submitting posts ...
was:

{
"id": 1,
"title": "заголовок"
}

became:
{
"id": 1,
"title": "заголовок",
"descr": "текст"
}

It comes to mind to take the folder containing the API with version 1.0.0 and copy it to another one, renaming it to 1.0.1 and working with the new version in the new folder...
But it turns out to be stupid to duplicate all the code for the sake of one parameter.. The
IF clause again comes to mind. Like: if the appeal is to version 1.0.0, then we give the first option, if 1.0.1 - the second.
But then again... after some time there will be so many of these IFs that I simply won't be able to control them....
Tell me how to separate these versions on the server with less problems...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-03-06
@yellow79

after some time there will be so many of these IFs

Why a lot? I think one is enough. Right at the entrance, you check the presence of a controller for the version specified in the request, if it is not there, downgrade the version and check the presence of the controller again, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question