A FastAPI + Pydantic extension for simplifying hypermedia-driven API development.
Project description
FastAPI-HyperModel
Simple hypermedia for FastAPI
Documentation: https://jtc42.github.io/fastapi-hypermodel/
Source Code: https://github.com/jtc42/fastapi-hypermodel
FastAPI-HyperModel is a FastAPI + Pydantic extension for simplifying hypermedia-driven API development.
This module adds a new Pydantic model base-class, supporting dynamic href
generation based on object data.
Model | Response |
---|---|
class ItemSummary(HyperModel):
name: str
id: str
href = UrlFor(
"read_item", {"item_id": "<id>"}
)
|
{
"name": "Foo",
"id": "item01",
"href": "/items/item01"
}
|
class ItemSummary(HyperModel):
name: str
id: str
link = HALFor(
"read_item", {"item_id": "<id>"},
description="Read an item"
)
|
{
"name": "Foo",
"id": "item01",
"link": {
"href": "/items/item01",
"method": "GET",
"description": "Read an item"
}
}
|
Installation
pip install fastapi-hypermodel
Limitations
Currently, query parameters will not resolve correctly. When generating a resource URL, ensure all parameters passed are path parameters, not query parameters.
This is an upstream issue, being tracked here.
Attributions
Huge thanks to @christoe for building support for Pydantic 2.
Some functionality is based on Flask-Marshmallow URLFor
class.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastapi_hypermodel-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d0e48f340fd5c5fea9e51e45ee94fbbd59e2a0f124af2787b1d822573ed800 |
|
MD5 | d3ee804c7b6033058882f99d3f3314e2 |
|
BLAKE2b-256 | cb43d6e5dc1bbdc1a296903f236acbd5734ed0f01756dd2b2104fd2e017f2cf4 |