Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/community-of-python/fast-version
Versioning APIs in FastAPI by Accept-header
https://github.com/community-of-python/fast-version
accept-header fastapi rest versioning
Last synced: 2 months ago
JSON representation
Versioning APIs in FastAPI by Accept-header
- Host: GitHub
- URL: https://github.com/community-of-python/fast-version
- Owner: community-of-python
- License: mit
- Created: 2023-09-07T18:52:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-20T07:30:55.000Z (6 months ago)
- Last Synced: 2024-07-20T08:40:56.828Z (6 months ago)
- Topics: accept-header, fastapi, rest, versioning
- Language: Python
- Homepage:
- Size: 312 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
FastAPI versioning library
==
[![Test Coverage](https://codecov.io/gh/community-of-python/fast-version/branch/main/graph/badge.svg)](https://codecov.io/gh/community-of-python/fast-version)
[![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)
[![Supported versions](https://img.shields.io/pypi/pyversions/fast-version.svg)](https://pypi.python.org/pypi/fast-version)
[![downloads](https://img.shields.io/pypi/dm/fast-version.svg)](https://pypistats.org/packages/fast-version)
[![GitHub stars](https://img.shields.io/github/stars/community-of-python/fast-version)](https://github.com/community-of-python/fast-version/stargazers)This package adds versioning by Accept-header into FastAPI
## Quickstart:
### Installation
```shell
$ pip install fast-version
```### Defining app and routes
```python
import fastapifrom 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
```bash
# 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'
```