Skip to main content

Add your description here

Project description

fastapi-header-versions

This package adds versioning by Accept-header into FastAPI

Defining app and routes

from enum import StrEnum
import fastapi

from fast_version import VersionedRouter, InlineVersionedRouter, init_fastapi_versioning


class AppType(StrEnum):
    some_name: "some.name"
    some_name2: "some.name2"


decorate_router = VersionedRouter()
inline_router = InlineVersionedRouter()


@decorate_router.get("/test/")
@decorate_router.set_api_version((1, 0), app_names={AppType.some_name, AppType.some_name2})
async def test_get() -> dict:
    return {"version": (1, 0)}


@inline_router.get("/test/", (2, 0), app_names=AppType.some_name)
async def test_get_v2() -> dict:
    return {"version": (2, 0)}


app = fastapi.FastAPI()
app.include_router(inline_router)
init_fastapi_versioning(app=app)

Query Examples

# call 1.0 version
curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json; version=1.0'

# call 2.0 version
curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json; version=2.0'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_header_versions-0.2.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_header_versions-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_header_versions-0.2.0.tar.gz.

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7e6694279a75a7eb96448c09c56414a5aad619f942a054fe78bcc2e0fd8f2de2
MD5 2db6e84f20dfa9742a507d33a17a181c
BLAKE2b-256 05e52651ec76ad5fffd60f1a20541f7b50da7d6ef2f74c8dc943bfee454a19c5

See more details on using hashes here.

File details

Details for the file fastapi_header_versions-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f5043373e82c735d9aa10103762c938ffc751f0b1ae1de478549a358931e1b6
MD5 2e2aedfe9821c9aaa162adf968750372
BLAKE2b-256 4ee6d28e3a81c97fb99d0e17aad16d54ab5ba087f594038a6d0bbcf0ef1d0c78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page