Home > front end >  serving multiple model version in springboot app - best approach
serving multiple model version in springboot app - best approach

Time:10-07

My application is based on some api, which has multiple versions. For example

  • v1: User (name : String, surname: String)
  • v2: User (name : String, surname: String, middleName: String) Is there a better solution than creating another POJO class for each version and creating another set of controllers, services etc.

Can someone give me a clue what i should look for?

CodePudding user response:

In my point of view, the best approach would be to have a versioned context path. Something like the following endpoints:

  • your-domain/v1/...
  • your-domain/v2/...

This means you would have at least 2 different Controllers (one for each version) and 2 different models. At some point in the future, you could simply drop one of them if you want to stick with one and your consumers have migrated to the other.

This is true if the differences between the models v1 and v2 are big. If they are not that many or if they are not that complex you might want to take a look at JSON Views.

  • Related