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.2.2.tar.gz
(26.5 kB
view details)
Built Distribution
File details
Details for the file fast_version-1.2.2.tar.gz
.
File metadata
- Download URL: fast_version-1.2.2.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c6324c86fd651e8ab20db297d82f3c96396241be3c7011b676460b94c68329 |
|
MD5 | 30b92ca4929683782a768136461f591a |
|
BLAKE2b-256 | 3b750157ad827e79306df8d8e1d32fa514ccf8972282fbcffd527e0788f8b83c |
File details
Details for the file fast_version-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: fast_version-1.2.2-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a384194c0ce3e776df4966e9f33fb9267e4bc42f48fd9a6e8ae00814ced97a |
|
MD5 | 7d364a63be6cc09f0c3cb08191b2dca7 |
|
BLAKE2b-256 | bfdac3a9309f7564faf40d4bdebe03524219f0e37eb2c96e7667b2ea2b7801a8 |