Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastapi-hypermodel

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastapi-hypermodel

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

  • 2.1.0
  • PyPI
  • Socket score

Maintainers
1

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.

FormatResponse

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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc