Versioning your API
API versioning is essential in maintaining and evolving web services without disrupting the existing users. It allows developers to introduce changes, improvements, or even breaking changes while providing backward compatibility. In this recipe, we will implement versioning in our Task Manager API.
Getting ready…
To follow the recipe, you will need to have endpoints already defined. If you don’t have them, you can first check the Creating RESTful endpoints recipe.
How to do it...
There are several strategies for API versioning. We will use the most common approach, URL path versioning, for our API.
Let’s consider that we want to improve the task information by adding a new str
field called priority
that is set to "lower"
by default. Let's do it through the following steps.
- Let’s create a
TaskV2
object class in themodels.py
module:from typing import Optional class TaskV2(BaseModel): &...