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.

Hypermedia consist of enriching API responses by providing links to other URIs within the services to fetch related resources or perform certain actions. There are several levels according to the Hypermedia Maturity Model Levels. Using Hypermedia makes APIs reach Level 3 of the Richardson Maturity Model (RMM), which involves leveraging Hypertext As The Engine Of Application State (HATEOAS), that is, Hypermedia.

Below are some examples of responses using hypermedia. For detailed examples, check the docs.

Format Response

No Hypermdia

{
    "id_": "item01",
    "name": "Foo",
    "price": 10.2,
}

Level 0 Hypermedia (URLFor)

{
    "id_": "item01",
    "name": "Foo",
    "price": 10.2,

    "href": "/items/item01",
    "update": "/items/item01"
}

Level 1 Hypermedia (HAL)

{
    "id_": "item01",
    "name": "Foo",
    "price": 10.2,

    "_links": {
        "self": {"href": "/items/item01"},
        "update": {"href": "/items/item01"},
    },
}

Level 2 Hypermedia (Siren)

{
    "properties": {
        "id_": "item01",
        "name": "Foo",
        "price": 10.2
    },
    "links": [
        {
            "rel": ["self"],
            "href": "/items/item01"
        }
    ],
    "actions": [
        {
            "name": "update",
            "method": "PUT",
            "href": "/items/item01",
            "type": "application/x-www-form-urlencoded",
            "fields": [
                {
                    "name": "name",
                    "type": "text",
                    "value": "Foo"
                },
                {
                    "name": "description",
                    "type": "text",
                    "value": "None"
                },
                {
                    "name": "price",
                    "type": "number",
                    "value": "10.2"
                }
            ]
        }
    ]
}

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.

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-2.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

fastapi_hypermodel-2.1.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_hypermodel-2.1.0.tar.gz.

File metadata

  • Download URL: fastapi_hypermodel-2.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.18 Linux/6.2.0-1019-azure

File hashes

Hashes for fastapi_hypermodel-2.1.0.tar.gz
Algorithm Hash digest
SHA256 fbab225c8440513dbfbc9993965224e76dfe46b533c9eedcf29217f65b5b2383
MD5 c795664c39fa40cc233967f9a84d631f
BLAKE2b-256 d332ca3d2742435f7e4330cd97a2715ba68c2f026fcfca938b914c2936e0ffff

See more details on using hashes here.

File details

Details for the file fastapi_hypermodel-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_hypermodel-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.18 Linux/6.2.0-1019-azure

File hashes

Hashes for fastapi_hypermodel-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 761a9bb4ad76c7d3159dfb6d21a577080c58db15db7a0c7c7512a8ea96dc9fca
MD5 c99a51e797ae36e0d34879b8c7b29588
BLAKE2b-256 b292e89a2916ff972c731b2e2f59871335113d233c37d69b2201d769c9fd53b6

See more details on using hashes here.

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