Fastapi versioning package with accept header
Project description
FastAPI versioning library
This package adds versioning by Accept-header into FastAPI
Quickstart:
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.0.0.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for fast_version-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0855acc079c60dde6ba1a89ec9948f90abe2d7a921a22f930e69b92c928061d9 |
|
MD5 | 8ce7c34d26c0f42164c8d729a3448d00 |
|
BLAKE2b-256 | 0b155305a95a8a57a6f6a8990eebbeac4df35bc63be0b9d94b14a4f3cacd1447 |