Skip to main content

A FastAPI + Pydantic extension for simplifying hypermedia-driven API development.

Project description

FastAPI-HyperModel

Simple hypermedia for FastAPI

Package version


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

Some functionality is based on Flask-Marshmallow URLFor class.

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

fastapi-hypermodel-0.4.0.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

fastapi_hypermodel-0.4.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page