Skip to main content

Fastapi versioning package with accept header

Project description

FastAPI versioning library

This package adds versioning by Accept-header into FastAPI

Quickstart:

Installation

$ pip install fast-version

Defining app and routes

import fastapi

from fast_version import VersionedAPIRouter, init_fastapi_versioning


VERSION_HEADER: str = "application/vnd.some.name+json"
ROUTER_OBJ = VersionedAPIRouter()


@ROUTER_OBJ.get("/test/")
async def test_get() -> dict:
    return {"version": (1, 0)}


@ROUTER_OBJ.get("/test/")
@ROUTER_OBJ.set_api_version((2, 0))
async def test_get_v2() -> dict:
    return {"version": (2, 0)}


app = fastapi.FastAPI()
app.include_router(ROUTER_OBJ)
init_fastapi_versioning(app=app, vendor_media_type=VERSION_HEADER)

Query Examples

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

curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json'

curl -X 'GET' 'https://test.ru/test/'

# 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

fast_version-1.1.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.

fast_version-1.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file fast_version-1.1.0.tar.gz.

File metadata

  • Download URL: fast_version-1.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for fast_version-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7b2360ff2834d843fee1c7cd6ae37aabc9a2eeaf1752a827678fa1ec4c056e62
MD5 a7cf8e884472c86f12a9d9c641099b64
BLAKE2b-256 db1b50adfdcfd860dc4f6c5954432372a6b9d02b6151e9b72c1db8246f347f8d

See more details on using hashes here.

File details

Details for the file fast_version-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: fast_version-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for fast_version-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5c82bf663d84bac88c8b832e47d39ae72bb23c73cb161dc144c627beba35290
MD5 5fd05a92283aff2e213de09408a68ce7
BLAKE2b-256 d95675089f80cd663f2c265cf5575a65912812f5ae661977e9de7913ccd516d3

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