Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing example for this case #51

Open
lcsvcn opened this issue Jan 26, 2024 · 1 comment
Open

Missing example for this case #51

lcsvcn opened this issue Jan 26, 2024 · 1 comment

Comments

@lcsvcn
Copy link

lcsvcn commented Jan 26, 2024

How to use in this format:

router = APIRouter()

router.get("/users")(get_users)

def get_users():
      # function logic here

Looked up all examples and could not find...

@alexschimpf
Copy link
Owner

This should work...

from typing import List, Any, Dict
from fastapi import FastAPI, APIRouter
from pydantic import BaseModel

from fastapi_versionizer.versionizer import Versionizer, api_version


app = FastAPI(
    title='test',
    docs_url='/swagger',
    openapi_url='/api_schema.json',
    redoc_url=None,
    description='Simple example of FastAPI Versionizer.',
    terms_of_service='https://github.com/alexschimpf/fastapi-versionizer'
)
items_router = APIRouter(
    prefix='/items',
    tags=['Items']
)


@api_version(1)
def get_items_v1() -> str:
    return 'v1'


@api_version(2)
def get_items_v2() -> str:
    return 'v2'


items_router.get('', deprecated=True)(get_items_v1)
items_router.get('')(get_items_v2)
app.include_router(items_router)

versions = Versionizer(
    app=app,
    prefix_format='/v{major}',
    semantic_version_format='{major}',
    latest_prefix='/latest',
    include_versions_route=True,
    sort_routes=True
).versionize()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants