Closed c-tanner closed 3 years ago
Actually, it will automatically add newer versions for each endpoint not redefined. I got this from https://medium.com/geoblinktech/fastapi-with-api-versioning-for-data-applications-2b178b0f843f
That's nice but I wonder how you remove an endpoint in a new version.
That's nice but I wonder how you remove an endpoint in a new version.
@beenje this is demonstrated in this example: https://github.com/DeanWay/fastapi-versioning/blob/master/example/annotation/store.py#L48-L51
🙂
@c-tanner for your example you can just specify the first version:
@app.get("/home")
@version(1, 0)
def home() -> str:
return "You are home."
if there are any later versions specified anywhere else then /home
will exist for those versions too. The general rule is that you specify the version when an endpoint was introduced or changed, and later versions will include the most recent change. You would only need to do something like the example you've given if you for some reason wanted to create some arbitrary new versions without changing or introducing any endpoint at all.
Currently, if we are to support multiple versions of an API with many endpoints, we need to duplicate each endpoint (even if logic does not change for every endpoint) in order to be backward compatible.
An array of values could be passed to
@version()
to allow a single method to support multiple versions. Example:Current:
Suggested: