Skip to main content

Fastapi versioning package with accept header

Project description

fastapi-header-versions

This package adds versioning by Accept-header into FastAPI

Installation

pip install fastapi-header-versions

Defining app and routes

from enum import StrEnum
import fastapi

from fastapi_header_version import VersionedRouter, InlineVersionedRouter, init_fastapi_versioning


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


router = VersionedRouter()
inline_router = InlineVersionedRouter()


@router.get("/test/")
@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/", version=1, app_names=AppType.some_name)
async def test_get_v1() -> dict:
    return {"version": (2, 0)}


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


app = fastapi.FastAPI()
app.include_router(router)
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.2.tar.gz (5.9 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.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.2.tar.gz
Algorithm Hash digest
SHA256 423d38ba3868a17e2078710179670fb8f2914200221699098fd742874c2d6022
MD5 85e21f190cfa9244684070e693112264
BLAKE2b-256 aabfd55b5523d3a96692639a1225481f10dbd146bc5a852ac0f1831848eca9a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23d3616a260e297be192f1bd5754dae25bb7accc456db045fd81f91c916b4fb9
MD5 672ed65f7b3b6677995673e45fdfac5c
BLAKE2b-256 548709817d8b7d98f52d9dd30c480e4ad071b5cca54ebbb8f55cfcef9d79a4ac

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