DeanWay / fastapi-versioning

api versioning for fastapi web applications
MIT License
642 stars 63 forks source link

Router with versioning #58

Open itomtom opened 2 years ago

itomtom commented 2 years ago

Is your feature request related to a problem? Please describe. Currently from the examples I've seen to have versioning on multiple router you need to proceed as such. Where you will need to create different router and append the versioning numbers yourself without using the @version decorator. Is there a more clear cut way to do this without creating different routers and use the version decorator

Describe the solution you'd like I would like to be able to version my routers similar to the examples in the README, so something like:

from fastapi import APIRouter
from fastapi_versioning import VersionedFastAPI, version

router = APIRouter(
    prefix="/greetings",
    tags=["greetings"],
)

@router.get("/hello")
@version(1)
def greet_with_hello():
    return "Hello"

@router.get("/hello")
@version(2)
def greet_with_hi():
    return "Hi"

router= VersionedFastAPI(router)

Describe alternatives you've considered I can proceed with the example listed in Issue 34. However, manually adding the version number to the url is something I would like to avoid.

Additional context

den4uk commented 1 year ago

I also found myself here, nearly wanting to write exactly the same issue as @itomtom. Versioning of a APIRouter makes a lot more sense, then a whole instance of FastAPI.