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/", (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.1.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.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b823012f499133e3670d3ebc32dd63a6ab72f8e4bc1fac639c6cef13f4b62fe9
MD5 91ea3914651a710a43a5d9cdc61d10e3
BLAKE2b-256 0eea2f2a67626a577bd7fcd2440b459963e2d1729e192265cb71d04944134986

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_header_versions-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 165076de85d4afc294f122ecbddef7eb69612a98e3f199a5c8f9df9715c22d4a
MD5 470daef30df3a436fcfe5b77e69a219b
BLAKE2b-256 a7eec9781a88c6dc4314c03d255a1cac54a701f763e708723268f83b3f8246bb

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