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.1.tar.gz
(26.6 kB
view details)
Built Distribution
File details
Details for the file fast_version-1.2.1.tar.gz
.
File metadata
- Download URL: fast_version-1.2.1.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4602de25a70d983bc52718425137a8740802336c3ad12d3ca539937b19b14e6 |
|
MD5 | 8cb7d3f32ad3c01d1747ebaa500155f1 |
|
BLAKE2b-256 | 1e48cbc97ea65e906d536c035152d7acf501ad392c339aaafb52dd8dd822ac9a |
File details
Details for the file fast_version-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: fast_version-1.2.1-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 | af6a9e1dee3b6252ceff37ddebc8be07ee28dc7d568b0c1279b9ac0e2795aed2 |
|
MD5 | 5ae5d9db7e2024cfdfea6b69589345c1 |
|
BLAKE2b-256 | 0f12815303e75bd96de920dc56f746f9015ec0add658a732362b12407f515fc4 |