Chapter 23 - Database/API Versioning and Migration

Not sure if I’m missing something however I went through this chapter and didn’t see anything on API Versioning… normally to me that means V1 API, V2 API etc… that can change end points logic etc…

Can you explain what you mean by API Versioning regarding this chapter?

@jonasschwartz Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @warplydesigned

Yeah it unfortunately didn’t make it into the current book, it will be part of the second edition.

Generally what you can do (and what i personally do) is to make a new route and either a new function or new controller, for example:

// GET /posts
router.get("posts", use: myFunc)

// GET /v2/posts
router.get("v2", "posts", use: myV2Func)

This way you can have a different output in func myV2Func()

This is of cause a very simple example :slight_smile:

Ok thanks for the update. I was looking forward to the versioning. Have been trying to decide if I should build a project with vapor or just stick with Django where I have been a lead Django developer for 6 years but am looking for a change…

@warplydesigned the above example is more or less what will be in the chapter (Of cause with more code samples) and should do the trick, it’s a fairly easy way to do versioning.

If you have some questions about it, feel free to ask, or join our Discord on http://vapor.team where a lot of different people can give feedback on ways to develop Vapor :slight_smile:

1 Like

Hi,

Please take a look in the below link where API versioning is explained well.
Don’t forget to check the videos listed in the playlist of this blog.

https://www.meritedin.com/blogs/api-versioning

Regards,

Sowthri S